當前位置: 首頁>>代碼示例>>Java>>正文


Java Expose類代碼示例

本文整理匯總了Java中com.google.gson.annotations.Expose的典型用法代碼示例。如果您正苦於以下問題:Java Expose類的具體用法?Java Expose怎麽用?Java Expose使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Expose類屬於com.google.gson.annotations包,在下文中一共展示了Expose類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doStuffWith

import com.google.gson.annotations.Expose; //導入依賴的package包/類
private static void doStuffWith(Class<?> clazz) {
    FeatureInfo featureInfo = clazz.getAnnotation(FeatureInfo.class);

    List<String> dependencies = new ArrayList<>();
    try {
        Class[] dep = (Class[]) clazz.getMethod("getDependencies").invoke(clazz.newInstance());
        for (Class c : dep) {
            dependencies.add(c.getName());
        }
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | InstantiationException e) {
        e.printStackTrace();
        System.out.println("could not collect dependencies for clazz " + clazz.getSimpleName());
    }

    List<String> params = new ArrayList<>();
    for (Field field : clazz.getDeclaredFields()) {
        if (field.isAnnotationPresent(Expose.class)) {
            params.add(field.getName() + " (" + field.getType().getName() + ")");
        }
    }

    Feature feature = new Feature(featureInfo.name(), clazz.getName(), featureInfo.author(), featureInfo.version(),
            featureInfo.description(), dependencies, params, slugify.slugify(clazz.getName()));
    System.out.println(feature);
    features.add(feature);
}
 
開發者ID:VoxelGamesLib,項目名稱:VoxelGamesLib,代碼行數:27,代碼來源:GenerateFeatures.java

示例2: toMap

import com.google.gson.annotations.Expose; //導入依賴的package包/類
public Map<String, Object> toMap(Object requestObject) {
    Map<String, Object> valuesToWrite = new HashMap<>();
    for (Field field : requestObject.getClass().getDeclaredFields()) {
        if (Modifier.isStatic(field.getModifiers())) {
            continue;
        }
        if (Modifier.isPrivate(field.getModifiers())) {
            continue;
        }
        Expose expose = field.getAnnotation(Expose.class);
        if (expose != null && !expose.serialize()) {
            continue;
        }
        Object value = ReflectionUtils.getValue(field, requestObject);
        if (value == null) {
            continue;
        }
        SerializedName serializedName = field.getAnnotation(SerializedName.class);
        String nameToUse = serializedName != null ? serializedName.value() : field.getName();
        Object valueToUse = determineCorrectValue(value);
        if (valueToUse != null) {
            valuesToWrite.put(nameToUse, valueToUse);
        }
    }
    return valuesToWrite;
}
 
開發者ID:vmware,項目名稱:workflowTools,代碼行數:27,代碼來源:MapObjectConverter.java

示例3: shouldHaveExposeAnnotationForField

import com.google.gson.annotations.Expose; //導入依賴的package包/類
@Test
@Parameters({
        "id",
        "label",
        "mandatory",
        "readOnly",
        "type",
        "uri",
        "visible",
        "masterDependencies",
        "slaveDependencies",
        "validationRules",
        "state",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = InputControl.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
 
開發者ID:Jaspersoft,項目名稱:js-android-sdk,代碼行數:19,代碼來源:InputControlTest.java

示例4: shouldHaveExposeAnnotationForField

import com.google.gson.annotations.Expose; //導入依賴的package包/類
@Test
@Parameters({
        "async",
        "freshData",
        "ignorePagination",
        "interactive",
        "saveDataSnapshot",
        "outputFormat",
        "pages",
        "transformerKey",
        "anchor",
        "baseUrl",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = ExecutionRequestOptions.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
 
開發者ID:Jaspersoft,項目名稱:js-android-sdk,代碼行數:18,代碼來源:ExecutionRequestOptionsTest.java

示例5: excludeField

import com.google.gson.annotations.Expose; //導入依賴的package包/類
public boolean excludeField(Field field, boolean serialize) {
    if ((this.modifiers & field.getModifiers()) != 0) {
        return true;
    }
    if (this.version != IGNORE_VERSIONS && !isValidVersion((Since) field.getAnnotation(Since.class), (Until) field.getAnnotation(Until.class))) {
        return true;
    }
    if (field.isSynthetic()) {
        return true;
    }
    if (this.requireExpose) {
        Expose annotation = (Expose) field.getAnnotation(Expose.class);
        if (annotation == null || (serialize ? !annotation.serialize() : !annotation.deserialize())) {
            return true;
        }
    }
    if (!this.serializeInnerClasses && isInnerClass(field.getType())) {
        return true;
    }
    if (isAnonymousOrLocal(field.getType())) {
        return true;
    }
    List<ExclusionStrategy> list = serialize ? this.serializationStrategies : this.deserializationStrategies;
    if (!list.isEmpty()) {
        FieldAttributes fieldAttributes = new FieldAttributes(field);
        for (ExclusionStrategy exclusionStrategy : list) {
            if (exclusionStrategy.shouldSkipField(fieldAttributes)) {
                return true;
            }
        }
    }
    return false;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:34,代碼來源:Excluder.java

示例6: SimpleDatabaseMap

import com.google.gson.annotations.Expose; //導入依賴的package包/類
public SimpleDatabaseMap(String table, String database, Class<K> keyClazz, Class<V> valueClazz, DatabaseType type) {
    this.handler = new SQLDatabaseHandler(table, database);

    this.keyColumnName = keyClazz.getSimpleName().toLowerCase();
    this.valueClazz = valueClazz;

    List<String> columnNames = new ArrayList<>();


    if (type == DatabaseType.MYSQL) {
        columnNames.add(SQLDatabaseHandler.createMySQLColumn(keyColumnName, MySQLDataType.VARCHAR, 767, SQLConstraints.PRIMARY_KEY));

        for (ReflectionHelper.SaveField valueFields : ReflectionHelper.findFieldsNotAnnotatedWith(Expose.class, valueClazz)) {
            columnNames.add(SQLDatabaseHandler.createMySQLColumn(
                    valueFields.field().getName(), MySQLDataType.TEXT, 5000));

            fieldNames.add(valueFields.field().getName());
        }
    } else if (type == DatabaseType.SQLITE) {
        columnNames.add(SQLDatabaseHandler.createSQLiteColumn(keyColumnName, SQLiteDataType.TEXT, SQLConstraints.PRIMARY_KEY));

        for (ReflectionHelper.SaveField sf : ReflectionHelper.findFieldsNotAnnotatedWith(Expose.class, valueClazz)) {
            columnNames.add(SQLDatabaseHandler.createSQLiteColumn(
                    sf.field().getName(), SQLiteDataType.TEXT));

            fieldNames.add(sf.field().getName());
        }
    }

    handler.create(columnNames.toArray(new String[columnNames.size()]));
}
 
開發者ID:AlphaHelixDev,項目名稱:AlphaLibary,代碼行數:32,代碼來源:SimpleDatabaseMap.java

示例7: save

import com.google.gson.annotations.Expose; //導入依賴的package包/類
private <T> JsonObject save(T type) {
    JsonObject obj = new JsonObject();

    for (ReflectionHelper.SaveField f : ReflectionHelper.findFieldsNotAnnotatedWith(Expose.class, type.getClass())) {
        if (f.field().getType().equals(String.class))
            f.set(type, f.get(type).toString().replace("§", "&"), true);
        obj.add(f.field().getName(), JSONUtil.getGson().toJsonTree(f.get(type)));
    }

    return obj;
}
 
開發者ID:AlphaHelixDev,項目名稱:AlphaLibary,代碼行數:12,代碼來源:SimpleConfigLoader.java

示例8: save

import com.google.gson.annotations.Expose; //導入依賴的package包/類
default <T extends ConfigValue> JsonObject save(T type) {
    JsonObject obj = new JsonObject();

    for (ReflectionHelper.SaveField f : ReflectionHelper.findFieldsNotAnnotatedWith(Expose.class, type.getClass())) {
        if (f.field().getType().equals(String.class))
            f.set(type, f.get(type).toString().replace("§", "&"), true);
        obj.add(f.field().getName(), JSONUtil.getGson().toJsonTree(f.get(type)));
    }

    return obj;
}
 
開發者ID:AlphaHelixDev,項目名稱:AlphaLibary,代碼行數:12,代碼來源:ConfigValue.java

示例9: routes

import com.google.gson.annotations.Expose; //導入依賴的package包/類
@Override
public RouteGroup routes() {
    return () -> {
        before("/*", (request, response) -> log.info("endpoint: " + request.pathInfo()));
        get("/", this::getTutorList, tutors -> {
            // Return only the required fields in JSON response
            Gson gson = new GsonBuilder()
                    .addSerializationExclusionStrategy(new ExclusionStrategy() {
                        @Override
                        public boolean shouldSkipField(FieldAttributes fieldAttributes) {
                            final Expose expose = fieldAttributes.getAnnotation(Expose.class);
                            // Skip "courseRequirements" field in tutor list deserialization
                            return expose == null
                                    || !expose.serialize()
                                    || (fieldAttributes.getDeclaringClass() == Course.class && fieldAttributes.getName().equals("courseRequirements"));
                        }

                        @Override
                        public boolean shouldSkipClass(Class<?> clazz) {
                            return false;
                        }
                    })
                    .setPrettyPrinting()
                    .create();
            return gson.toJson(tutors);
        });
        get("/:id", this::getTutor, gson::toJson);
    };
}
 
開發者ID:cocolocomoco21,項目名稱:ULCRS,代碼行數:30,代碼來源:TutorController.java

示例10: excludeField

import com.google.gson.annotations.Expose; //導入依賴的package包/類
public boolean excludeField(Field field, boolean serialize) {
    if ((this.modifiers & field.getModifiers()) != 0) {
        return true;
    }
    if (this.version != IGNORE_VERSIONS && !isValidVersion((Since) field.getAnnotation(Since
            .class), (Until) field.getAnnotation(Until.class))) {
        return true;
    }
    if (field.isSynthetic()) {
        return true;
    }
    if (this.requireExpose) {
        Expose annotation = (Expose) field.getAnnotation(Expose.class);
        if (annotation == null || (serialize ? !annotation.serialize() : !annotation
                .deserialize())) {
            return true;
        }
    }
    if (!this.serializeInnerClasses && isInnerClass(field.getType())) {
        return true;
    }
    if (isAnonymousOrLocal(field.getType())) {
        return true;
    }
    List<ExclusionStrategy> list = serialize ? this.serializationStrategies : this
            .deserializationStrategies;
    if (!list.isEmpty()) {
        FieldAttributes fieldAttributes = new FieldAttributes(field);
        for (ExclusionStrategy exclusionStrategy : list) {
            if (exclusionStrategy.shouldSkipField(fieldAttributes)) {
                return true;
            }
        }
    }
    return false;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:37,代碼來源:Excluder.java

示例11: processNamedAsRule

import com.google.gson.annotations.Expose; //導入依賴的package包/類
@Override
public void processNamedAsRule(FieldSpec.Builder fieldSpec, FieldModel fieldModel) {
    String jsonProperty = fieldModel.getNamedAs();
    AnnotationSpec annotationSpec = AnnotationSpec.builder(SerializedName.class)
            .addMember("value", "$S", jsonProperty)
            .build();
    fieldSpec.addAnnotation(annotationSpec);
    fieldSpec.addAnnotation(Expose.class);
}
 
開發者ID:flipkart-incubator,項目名稱:Lyrics,代碼行數:10,代碼來源:GsonStyle.java

示例12: shouldSkipField

import com.google.gson.annotations.Expose; //導入依賴的package包/類
public boolean shouldSkipField(FieldAttributes f) {
  Expose annotation = f.getAnnotation(Expose.class);
  if (annotation == null) {
    return true;
  }
  return !annotation.serialize();
}
 
開發者ID:IAmPhoenix,項目名稱:Minecraft-API-Protocol,代碼行數:8,代碼來源:ExposeAnnotationSerializationExclusionStrategy.java

示例13: shouldSkipField

import com.google.gson.annotations.Expose; //導入依賴的package包/類
public boolean shouldSkipField(FieldAttributes f) {
  Expose annotation = f.getAnnotation(Expose.class);
  if (annotation == null) {
    return true;
  }
  return !annotation.deserialize();
}
 
開發者ID:IAmPhoenix,項目名稱:Minecraft-API-Protocol,代碼行數:8,代碼來源:ExposeAnnotationDeserializationExclusionStrategy.java

示例14: shouldSkipField

import com.google.gson.annotations.Expose; //導入依賴的package包/類
@Override
public boolean shouldSkipField(final FieldAttributes fieldAttributes) {
    Expose exposeAnnotation = fieldAttributes.getAnnotation(Expose.class);
    if (exposeAnnotation == null) {
        return false;
    }
    if (useForSerialization) {
        return !exposeAnnotation.serialize();
    }
    return !exposeAnnotation.deserialize();
}
 
開發者ID:vmware,項目名稱:workflowTools,代碼行數:12,代碼來源:ImprovedExclusionStrategy.java

示例15: fromMap

import com.google.gson.annotations.Expose; //導入依賴的package包/類
public <T> T fromMap(Map values, Class<T> objectClass) {
    Object createdObject = ReflectionUtils.newInstance(objectClass);
    for (Field field : objectClass.getDeclaredFields()) {
        if (Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())) {
            continue;
        }

        Expose exposeAnnotation = field.getAnnotation(Expose.class);
        if (exposeAnnotation != null && !exposeAnnotation.deserialize()) {
            continue;
        }

        String nameToUse = determineNameToUseForField(field);

        if (!values.containsKey(nameToUse)) {
            continue;
        }

        Object valueToConvert = values.get(nameToUse);

        setFieldValue(createdObject, field, valueToConvert);
    }

    new PostDeserializeHandler().invokePostDeserializeMethods(createdObject);

    return (T) createdObject;
}
 
開發者ID:vmware,項目名稱:workflowTools,代碼行數:28,代碼來源:MapObjectConverter.java


注:本文中的com.google.gson.annotations.Expose類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。