@Override public void propertyField(JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) { field.annotate(JsonProperty.class).param("value", propertyName); if (field.type().erasure().equals(field.type().owner().ref(Set.class))) { field.annotate(JsonDeserialize.class).param("as", LinkedHashSet.class); } if (propertyNode.has("javaJsonView")) { field.annotate(JsonView.class).param( "value", field.type().owner().ref(propertyNode.get("javaJsonView").asText())); } if (propertyNode.has("description")) { field.annotate(JsonPropertyDescription.class).param("value", propertyNode.get("description").asText()); } }
@Test public void annotationStyleJackson2ProducesJsonPropertyDescription() throws Exception { Class<?> generatedType = schemaRule.generateAndCompile("/schema/description/description.json", "com.example", config("annotationStyle", "jackson2")).loadClass("com.example.Description"); Field field = generatedType.getDeclaredField("description"); assertThat(field.getAnnotation(JsonPropertyDescription.class).value(), is("A description for this property")); }
private void getInfoForClass(List<Map<String, String>> rows, Class<?> clazz, String prefix) throws Exception { Object instance = clazz.newInstance(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); String fieldName = field.getName(); String description = null; boolean isRequired = false; Object defaultValue = null; try { defaultValue = field.get(instance); } catch (IllegalArgumentException e) { } for (Annotation annotation : field.getAnnotations()) { if (annotation instanceof JsonProperty) { JsonProperty propAnn = (JsonProperty) annotation; String name = propAnn.value(); if (!StringUtils.isEmpty(name)) { fieldName = name; } isRequired = propAnn.required(); } if (annotation instanceof JsonPropertyDescription) { JsonPropertyDescription descAnn = (JsonPropertyDescription) annotation; description = descAnn.value(); } } if (hasGenerateDocumentation(field)) { getInfoForClass(rows, field.getType(), fieldName); } else if (description != null) { Map<String, String> entries = new HashMap<>(); if (prefix != null) { fieldName = prefix + "." + fieldName; } String type = field.getType().getSimpleName().toLowerCase(); entries.put("key", fieldName); entries.put("description", description); entries.put("type", type.toLowerCase()); entries.put("defaultValue", String.valueOf(defaultValue)); entries.put("required", String.valueOf(isRequired)); rows.add(entries); } } }
@JsonProperty("id") @JsonPropertyDescription("A unique identifier for the entity, can be either URI or CURIE") @JsonldId public String getId();
@JsonProperty("label") @JsonPropertyDescription("A string that contains the preferred natural language term to denote the entity") @JsonldProperty("http://www.w3.org/2000/01/rdf-schema#label") public String getLabel();
@JsonProperty("evidence") @JsonPropertyDescription("Any Association can have any number of pieces of evidence attached") public List<Evidence> getEvidence();
@JsonProperty(value = "schema") @JsonPropertyDescription("The type of this param") public JsonSchema getType() throws JsonMappingException { return Document.toJsonSchema(type); }
@JsonProperty(value = "schema") @JsonPropertyDescription("The return type.") public JsonSchema getReturn() throws JsonMappingException { return Document.toJsonSchema(returnType); }
/** * Return the type of the field schema. * * @return Field schema type */ @JsonProperty(required = true) @JsonPropertyDescription("Type of the field.") String getType();
/** * Return the label of the field schema. * * @return Label */ @JsonProperty(required = false) @JsonPropertyDescription("Label of the field.") String getLabel();
/** * Return the name of the field schema. * * @return Name */ @JsonProperty(required = true) @JsonPropertyDescription("Name of the field.") String getName();