Java 类com.google.gson.annotations.Expose 实例源码

项目:VoxelGamesLib    文件:GenerateFeatures.java   
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);
}
项目:workflowTools    文件:MapObjectConverter.java   
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;
}
项目:js-android-sdk    文件:InputControlTest.java   
@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));
}
项目:js-android-sdk    文件:ExecutionRequestOptionsTest.java   
@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));
}
项目:letv    文件:Excluder.java   
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;
}
项目:AlphaLibary    文件:SimpleDatabaseMap.java   
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()]));
}
项目:AlphaLibary    文件:SimpleConfigLoader.java   
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;
}
项目:AlphaLibary    文件:ConfigValue.java   
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;
}
项目:ULCRS    文件:TutorController.java   
@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);
    };
}
项目:boohee_v5.6    文件:Excluder.java   
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;
}
项目:Lyrics    文件:GsonStyle.java   
@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);
}
项目:Minecraft-API-Protocol    文件:ExposeAnnotationSerializationExclusionStrategy.java   
public boolean shouldSkipField(FieldAttributes f) {
  Expose annotation = f.getAnnotation(Expose.class);
  if (annotation == null) {
    return true;
  }
  return !annotation.serialize();
}
项目:Minecraft-API-Protocol    文件:ExposeAnnotationDeserializationExclusionStrategy.java   
public boolean shouldSkipField(FieldAttributes f) {
  Expose annotation = f.getAnnotation(Expose.class);
  if (annotation == null) {
    return true;
  }
  return !annotation.deserialize();
}
项目:workflowTools    文件:ImprovedExclusionStrategy.java   
@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();
}
项目:workflowTools    文件:MapObjectConverter.java   
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;
}
项目:swagger-jaxrs-maven    文件:GsonIntrospector.java   
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;
}
项目:js-android-sdk    文件:ValidationRuleTest.java   
@Test
@Parameters({
        "type",
        "errorMessage",
        "value",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = ValidationRule.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:InputControlStateTest.java   
@Test
@Parameters({
        "id",
        "uri",
        "value",
        "error",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = InputControlState.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:InputControlOptionTest.java   
@Test
@Parameters({
        "label",
        "value",
        "selected",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = InputControlOption.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:InputControlDashboardComponentTest.java   
@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));
}
项目:js-android-sdk    文件:DashboardComponentTest.java   
@Test
@Parameters({
        "id",
        "type",
        "name",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = DashboardComponent.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:ReportLookupTest.java   
@Test
@Parameters({
        "alwaysPromptControls",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = ReportLookup.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:ResourceLookupJsonConvertTest.java   
@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));
}
项目:js-android-sdk    文件:JobUnitSimpleTriggerTest.java   
@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));
}
项目:js-android-sdk    文件:JobUnitSimpleTriggerTest.java   
@Test
@Parameters({
        "occurrenceCount",
        "recurrenceInterval",
        "recurrenceIntervalUnit",
})
public void shouldHaveExposeAnnotationForFields(String fieldName) throws NoSuchFieldException {
    Field field = JobSimpleTriggerEntity.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:JobUnitOutputFormatsTest.java   
@Test
@Parameters({
        "outputFormat",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = JobOutputFormatsEntity.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:JobUnitTriggerTest.java   
@Test
@Parameters({
        "simpleTrigger",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = JobTriggerWrapper.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:JobUnitTest.java   
@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));
}
项目:js-android-sdk    文件:JobUnitSourceTest.java   
@Test
@Parameters({
        "folderURI",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = RepositoryDestinationEntity.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:RepositoryDestinationEntityTest.java   
@Test
@Parameters({
        "reportUnitURI",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = JobSourceEntity.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:JobUnitFormTest.java   
@Test
@Parameters({
        "label",
        "description",
        "baseOutputFilename",
        "source",
        "repositoryDestination",
        "outputFormats",
        "trigger",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = JobFormEntity.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:ErrorDescriptorTest.java   
@Test
@Parameters({
        "errorCode",
        "message",
        "parameters",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = ErrorDescriptor.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:OutputResourceDescriptorTest.java   
@Test
@Parameters({
        "contentType",
        "fileName",
        "outputFinal",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = OutputResourceDescriptor.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:ReportExecutionDescriptorTest.java   
@Test
@Parameters({
        "reportURI",
        "executionId",
        "status",
        "currentPage",
        "totalPages",
        "exports",
        "errorDescriptor",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = ReportExecutionDescriptor.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:AttachmentDescriptorTest.java   
@Test
@Parameters({
        "contentType",
        "fileName",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = AttachmentDescriptor.class.getDeclaredField(fieldName);
    MatcherAssert.assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:ExportDescriptorTest.java   
@Test
@Parameters({
        "id",
        "status",
        "outputResource",
        "attachments",
        "errorDescriptor",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = ExportDescriptor.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:ExecutionStatusTest.java   
@Test
@Parameters({
        "value",
        "errorDescriptor",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = ExecutionStatus.class.getDeclaredField(fieldName);
    MatcherAssert.assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:ReportExecutionSearchResponseTest.java   
@Test
@Parameters({
        "items",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = ReportExecutionSearchResponse.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:EncryptionKeyTest.java   
@Test
@Parameters({
        "error",
        "exponent",
        "maxdigits",
        "modulus",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = EncryptionKey.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}
项目:js-android-sdk    文件:ServerInfoDataTest.java   
@Test
@Parameters({
        "dateFormatPattern",
        "datetimeFormatPattern",
        "version",
        "edition",
        "licenseType",
        "build",
        "editionName",
        "features",
})
public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException {
    Field field = ServerInfoData.class.getDeclaredField(fieldName);
    assertThat(field, hasAnnotation(Expose.class));
}