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); }
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; }
@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)); }
@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)); }
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; }
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()])); }
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; }
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; }
@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); }; }
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; }
@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); }
public boolean shouldSkipField(FieldAttributes f) { Expose annotation = f.getAnnotation(Expose.class); if (annotation == null) { return true; } return !annotation.serialize(); }
public boolean shouldSkipField(FieldAttributes f) { Expose annotation = f.getAnnotation(Expose.class); if (annotation == null) { return true; } return !annotation.deserialize(); }
@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(); }
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; }
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; }
@Test @Parameters({ "type", "errorMessage", "value", }) public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException { Field field = ValidationRule.class.getDeclaredField(fieldName); assertThat(field, hasAnnotation(Expose.class)); }
@Test @Parameters({ "id", "uri", "value", "error", }) public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException { Field field = InputControlState.class.getDeclaredField(fieldName); assertThat(field, hasAnnotation(Expose.class)); }
@Test @Parameters({ "label", "value", "selected", }) public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException { Field field = InputControlOption.class.getDeclaredField(fieldName); assertThat(field, hasAnnotation(Expose.class)); }
@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)); }
@Test @Parameters({ "id", "type", "name", }) public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException { Field field = DashboardComponent.class.getDeclaredField(fieldName); assertThat(field, hasAnnotation(Expose.class)); }
@Test @Parameters({ "alwaysPromptControls", }) public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException { Field field = ReportLookup.class.getDeclaredField(fieldName); assertThat(field, hasAnnotation(Expose.class)); }
@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)); }
@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)); }
@Test @Parameters({ "occurrenceCount", "recurrenceInterval", "recurrenceIntervalUnit", }) public void shouldHaveExposeAnnotationForFields(String fieldName) throws NoSuchFieldException { Field field = JobSimpleTriggerEntity.class.getDeclaredField(fieldName); assertThat(field, hasAnnotation(Expose.class)); }
@Test @Parameters({ "outputFormat", }) public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException { Field field = JobOutputFormatsEntity.class.getDeclaredField(fieldName); assertThat(field, hasAnnotation(Expose.class)); }
@Test @Parameters({ "simpleTrigger", }) public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException { Field field = JobTriggerWrapper.class.getDeclaredField(fieldName); assertThat(field, hasAnnotation(Expose.class)); }
@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)); }
@Test @Parameters({ "folderURI", }) public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException { Field field = RepositoryDestinationEntity.class.getDeclaredField(fieldName); assertThat(field, hasAnnotation(Expose.class)); }
@Test @Parameters({ "reportUnitURI", }) public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException { Field field = JobSourceEntity.class.getDeclaredField(fieldName); assertThat(field, hasAnnotation(Expose.class)); }
@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)); }
@Test @Parameters({ "errorCode", "message", "parameters", }) public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException { Field field = ErrorDescriptor.class.getDeclaredField(fieldName); assertThat(field, hasAnnotation(Expose.class)); }
@Test @Parameters({ "contentType", "fileName", "outputFinal", }) public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException { Field field = OutputResourceDescriptor.class.getDeclaredField(fieldName); assertThat(field, hasAnnotation(Expose.class)); }
@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)); }
@Test @Parameters({ "contentType", "fileName", }) public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException { Field field = AttachmentDescriptor.class.getDeclaredField(fieldName); MatcherAssert.assertThat(field, hasAnnotation(Expose.class)); }
@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)); }
@Test @Parameters({ "value", "errorDescriptor", }) public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException { Field field = ExecutionStatus.class.getDeclaredField(fieldName); MatcherAssert.assertThat(field, hasAnnotation(Expose.class)); }
@Test @Parameters({ "items", }) public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException { Field field = ReportExecutionSearchResponse.class.getDeclaredField(fieldName); assertThat(field, hasAnnotation(Expose.class)); }
@Test @Parameters({ "error", "exponent", "maxdigits", "modulus", }) public void shouldHaveExposeAnnotationForField(String fieldName) throws NoSuchFieldException { Field field = EncryptionKey.class.getDeclaredField(fieldName); assertThat(field, hasAnnotation(Expose.class)); }
@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)); }