com.fasterxml.jackson.annotation.JsonPropertyDescription Java Examples
The following examples show how to use
com.fasterxml.jackson.annotation.JsonPropertyDescription.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JacksonModule.java From jsonschema-generator with Apache License 2.0 | 5 votes |
/** * Determine the given type's associated "description" in the following order of priority. * <ol> * <li>{@link JsonPropertyDescription} annotation on the field itself</li> * <li>{@link JsonPropertyDescription} annotation on the field's getter method</li> * </ol> * * @param field field for which to collect an available description * @return successfully looked-up description (or {@code null}) */ protected String resolveDescription(FieldScope field) { if (field.isFakeContainerItemScope()) { return null; } // look for property specific description JsonPropertyDescription propertyAnnotation = field.getAnnotationConsideringFieldAndGetter(JsonPropertyDescription.class); if (propertyAnnotation != null) { return propertyAnnotation.value(); } return null; }
Example #2
Source File: Jackson2Parser.java From typescript-generator with MIT License | 5 votes |
private DeclarationModel parseEnumOrObjectEnum(SourceType<Class<?>> sourceClass, List<String> classComments) { final JsonFormat jsonFormat = sourceClass.type.getAnnotation(JsonFormat.class); if (jsonFormat != null && jsonFormat.shape() == JsonFormat.Shape.OBJECT) { return parseBean(sourceClass, classComments); } final boolean isNumberBased = jsonFormat != null && ( jsonFormat.shape() == JsonFormat.Shape.NUMBER || jsonFormat.shape() == JsonFormat.Shape.NUMBER_FLOAT || jsonFormat.shape() == JsonFormat.Shape.NUMBER_INT); final List<EnumMemberModel> enumMembers = new ArrayList<>(); if (sourceClass.type.isEnum()) { final Class<?> enumClass = (Class<?>) sourceClass.type; final Field[] allEnumFields = enumClass.getDeclaredFields(); final List<Field> constants = Arrays.stream(allEnumFields).filter(Field::isEnumConstant).collect(Collectors.toList()); for (Field constant : constants) { Object value; try { constant.setAccessible(true); final String enumJson = objectMapper.writeValueAsString(constant.get(null)); value = objectMapper.readValue(enumJson, new TypeReference<Object>(){}); } catch (Throwable e) { TypeScriptGenerator.getLogger().error(String.format("Cannot get enum value for constant '%s.%s'", enumClass.getName(), constant.getName())); TypeScriptGenerator.getLogger().verbose(Utils.exceptionToString(e)); value = constant.getName(); } final List<String> constantComments = getComments(constant.getAnnotation(JsonPropertyDescription.class)); if (value instanceof String) { enumMembers.add(new EnumMemberModel(constant.getName(), (String) value, constantComments)); } else if (value instanceof Number) { enumMembers.add(new EnumMemberModel(constant.getName(), (Number) value, constantComments)); } else { TypeScriptGenerator.getLogger().warning(String.format("'%s' enum as a @JsonValue that isn't a String or Number, ignoring", enumClass.getName())); } } } return new EnumModel(sourceClass.type, isNumberBased ? EnumKind.NumberBased : EnumKind.StringBased, enumMembers, classComments); }
Example #3
Source File: JacksonModuleTest.java From jsonschema-generator with Apache License 2.0 | 4 votes |
@JsonPropertyDescription(value = "getter description 1") public Float getFieldWithDescriptionOnGetter() { return this.fieldWithDescriptionOnGetter; }
Example #4
Source File: JacksonModuleTest.java From jsonschema-generator with Apache License 2.0 | 4 votes |
@JsonPropertyDescription(value = "getter description 2") public Long getFieldWithDescriptionAndOnGetter() { return fieldWithDescriptionAndOnGetter; }
Example #5
Source File: Jackson2Parser.java From typescript-generator with MIT License | 4 votes |
private static List<String> getComments(JsonPropertyDescription propertyDescriptionAnnotation) { final String propertyDescriptionValue = propertyDescriptionAnnotation != null ? propertyDescriptionAnnotation.value() : null; final List<String> propertyComments = Utils.splitMultiline(propertyDescriptionValue, false); return propertyComments; }