当前位置: 首页>>代码示例>>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;未经允许,请勿转载。