I'm attempting to use Jackson to generate JSON schemas from POJOs. Jackson has two ways to do this. This is the first:
ObjectMapper mapper = new ObjectMapper();
JsonSchema schema = mapper.generateJsonSchema(Entity.class);
String schemaString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema);
This is fine - it generates exactly what you'd expect.
{
"type" : "object",
"properties" : {
"pedigreeIds" : {
"type" : "array",
"items" : {
"type" : "string"
}
},
...
}
}
However, this approach is deprecated in favor of the second, which uses jackson-module-jsonschema:
ObjectMapper mapper = new ObjectMapper();
SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
mapper.acceptJsonFormatVisitor(mapper.constructType(Entity.class), visitor);
JsonSchema schema = visitor.finalSchema();
String schemaString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema);
Using this code spits out the following for the same entity class:
{
"$ref" : null,
"$schema" : null,
"disallow" : null,
"id" : null,
"required" : null,
"description" : null,
"title" : null,
"enums" : [ ],
"additionalProperties" : null,
"dependencies" : [ ],
"patternProperties" : { },
"properties" : {
"observationTime" : {
"$ref" : null,
"$schema" : null,
"disallow" : null,
...
}
}
}
Given that the first method is deprecated, I'd prefer to use the second if possible. I can't find any differences between what I'm doing and what various code snippets on the internet are doing.
Is there a configuration switch I'm missing, or something I'm simply doing wrong in the second example that causes Jackson to not generate the expected schema?