java类com.google.gson.annotations.Expose的实例源码

GenerateFeatures.java 文件源码 项目:VoxelGamesLib 阅读 26 收藏 0 点赞 0 评论 0
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);
}
MapObjectConverter.java 文件源码 项目:workflowTools 阅读 28 收藏 0 点赞 0 评论 0
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;
}
InputControlTest.java 文件源码 项目:js-android-sdk 阅读 23 收藏 0 点赞 0 评论 0
@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));
}
ExecutionRequestOptionsTest.java 文件源码 项目:js-android-sdk 阅读 26 收藏 0 点赞 0 评论 0
@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));
}
Excluder.java 文件源码 项目:letv 阅读 27 收藏 0 点赞 0 评论 0
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;
}
SimpleDatabaseMap.java 文件源码 项目:AlphaLibary 阅读 26 收藏 0 点赞 0 评论 0
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()]));
}
SimpleConfigLoader.java 文件源码 项目:AlphaLibary 阅读 28 收藏 0 点赞 0 评论 0
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;
}
ConfigValue.java 文件源码 项目:AlphaLibary 阅读 26 收藏 0 点赞 0 评论 0
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;
}
TutorController.java 文件源码 项目:ULCRS 阅读 29 收藏 0 点赞 0 评论 0
@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);
    };
}
Excluder.java 文件源码 项目:boohee_v5.6 阅读 28 收藏 0 点赞 0 评论 0
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;
}
GsonStyle.java 文件源码 项目:Lyrics 阅读 23 收藏 0 点赞 0 评论 0
@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);
}
ExposeAnnotationSerializationExclusionStrategy.java 文件源码 项目:Minecraft-API-Protocol 阅读 27 收藏 0 点赞 0 评论 0
public boolean shouldSkipField(FieldAttributes f) {
  Expose annotation = f.getAnnotation(Expose.class);
  if (annotation == null) {
    return true;
  }
  return !annotation.serialize();
}
ExposeAnnotationDeserializationExclusionStrategy.java 文件源码 项目:Minecraft-API-Protocol 阅读 29 收藏 0 点赞 0 评论 0
public boolean shouldSkipField(FieldAttributes f) {
  Expose annotation = f.getAnnotation(Expose.class);
  if (annotation == null) {
    return true;
  }
  return !annotation.deserialize();
}
ImprovedExclusionStrategy.java 文件源码 项目:workflowTools 阅读 23 收藏 0 点赞 0 评论 0
@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();
}
MapObjectConverter.java 文件源码 项目:workflowTools 阅读 41 收藏 0 点赞 0 评论 0
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;
}
GsonIntrospector.java 文件源码 项目:swagger-jaxrs-maven 阅读 25 收藏 0 点赞 0 评论 0
private boolean isExcluded(Field f) {
    int modifiers = f.getModifiers();
    if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers)) {
        return true;
    }
    Expose expose = f.getAnnotation(Expose.class);
    if (expose != null && !expose.deserialize() && !expose.serialize()) {
        return true;
    }
    return false;
}
ValidationRuleTest.java 文件源码 项目:js-android-sdk 阅读 26 收藏 0 点赞 0 评论 0
@Test
@Parameters({
        "type",
        "errorMessage",
        "value",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = ValidationRule.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
InputControlStateTest.java 文件源码 项目:js-android-sdk 阅读 30 收藏 0 点赞 0 评论 0
@Test
@Parameters({
        "id",
        "uri",
        "value",
        "error",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = InputControlState.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
InputControlOptionTest.java 文件源码 项目:js-android-sdk 阅读 27 收藏 0 点赞 0 评论 0
@Test
@Parameters({
        "label",
        "value",
        "selected",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = InputControlOption.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
InputControlDashboardComponentTest.java 文件源码 项目:js-android-sdk 阅读 26 收藏 0 点赞 0 评论 0
@Test
@Parameters({
        "label",
        "ownerResourceId",
        "ownerResourceParameterName",
        "parentId",
        "resource",
        "position",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = InputControlDashboardComponent.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
DashboardComponentTest.java 文件源码 项目:js-android-sdk 阅读 27 收藏 0 点赞 0 评论 0
@Test
@Parameters({
        "id",
        "type",
        "name",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = DashboardComponent.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
ReportLookupTest.java 文件源码 项目:js-android-sdk 阅读 23 收藏 0 点赞 0 评论 0
@Test
@Parameters({
        "alwaysPromptControls",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = ReportLookup.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
ResourceLookupJsonConvertTest.java 文件源码 项目:js-android-sdk 阅读 66 收藏 0 点赞 0 评论 0
@Test
@Parameters({
        "label",
        "description",
        "uri",
        "resourceType",
        "version",
        "creationDate",
        "updateDate",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = ResourceLookup.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
JobUnitSimpleTriggerTest.java 文件源码 项目:js-android-sdk 阅读 28 收藏 0 点赞 0 评论 0
@Test
@Parameters({
        "timezone",
        "calendarName",
        "startType",
        "startDate",
        "endDate",
        "misfireInstruction",
})
public void shouldHaveExposeAnnotationForSubclassFields(String fieldName) throws NoSuchFieldException {
    Field field = JobTriggerEntity.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
JobUnitSimpleTriggerTest.java 文件源码 项目:js-android-sdk 阅读 26 收藏 0 点赞 0 评论 0
@Test
@Parameters({
        "occurrenceCount",
        "recurrenceInterval",
        "recurrenceIntervalUnit",
})
public void shouldHaveExposeAnnotationForFields(String fieldName) throws NoSuchFieldException {
    Field field = JobSimpleTriggerEntity.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
JobUnitOutputFormatsTest.java 文件源码 项目:js-android-sdk 阅读 25 收藏 0 点赞 0 评论 0
@Test
@Parameters({
        "outputFormat",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = JobOutputFormatsEntity.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
JobUnitTriggerTest.java 文件源码 项目:js-android-sdk 阅读 27 收藏 0 点赞 0 评论 0
@Test
@Parameters({
        "simpleTrigger",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = JobTriggerWrapper.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
JobUnitTest.java 文件源码 项目:js-android-sdk 阅读 30 收藏 0 点赞 0 评论 0
@Test
@Parameters({
        "id",
        "version",
        "reportUnitURI",
        "label",
        "reportLabel",
        "owner",
        "state",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = JobUnitEntity.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
JobUnitSourceTest.java 文件源码 项目:js-android-sdk 阅读 26 收藏 0 点赞 0 评论 0
@Test
@Parameters({
        "folderURI",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = RepositoryDestinationEntity.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
RepositoryDestinationEntityTest.java 文件源码 项目:js-android-sdk 阅读 24 收藏 0 点赞 0 评论 0
@Test
@Parameters({
        "reportUnitURI",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = JobSourceEntity.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}


问题


面经


文章

微信
公众号

扫码关注公众号