FasterXML / jackson-annotations

Core annotations (annotations that only depend on jackson-core) for Jackson data processor
https://github.com/FasterXML/jackson
Apache License 2.0
1.03k stars 330 forks source link

Consider adding new @JsonClassDescription #73

Closed ufoscout closed 8 years ago

ufoscout commented 9 years ago

With version 2.3 the new @JsonPropertyDescription annotation has been introduced to define a human readable description for a logical property. It would be good to have an equivalent annotation at class level to add a description to be used by the JSON schema generator. Today the only way of providing a class level description is setting it manually to the JsonSchema object during the schema generation, e.g.:

JavaType type = mapper.getTypeFactory().constructParametricType(messageType.getTypeClass(), beanClass);
SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
mapper.acceptJsonFormatVisitor(type, visitor);
JsonSchema schema = visitor.finalSchema();
schema.setDescription(description);
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema);

The real drawback of the current solution is that the description itself cannot be saved with the class itself. The use of a @JsonClassDescription annotation would permit to have the description embedded within the class in a more coherent way.

cowtowncoder commented 9 years ago

Sounds reasonable, this could go in 2.7. Would just need addition of the annotation, a discovery method in AnnotationIntrospector (of jackson-databind), and schema generator to use it.

cowtowncoder commented 8 years ago

Added annotation, need to add support in jackson-databind as well.