Generating JSON Schemas with Jackson
Ability to generate JSON Schemas is a feature included in Jackson release 1.1.
Generation is done by serializing an instance of a Java class: serialization settings (global, annotation-based configuration) active at this point define actual schema definition. Result of generation is a JsonSchema object, which essentially contains an instance of Tree Model that can be serialized as String to produce externally usable schema document.
Here is an example of JSON Schema generation:
ObjectMapper mapper = new ObjectMapper(); JsonSchema jsonSchema = mapper.generateJsonSchema(SimpleBean.class);
and String serialization of the schema is done by:
String schemaStr = jsonSchema.toString();
or if additional modification is needed:
JsonNode schemaRootNode = jsonSchema.getSchemaNode()
