I intend to convert my POJOs to a JSON Schema.
In the existing POJOs we have annotations from the codehaus package:
@JsonProperty("address") where the corresponding import is:
import org.codehaus.jackson.annotate.JsonProperty;
I can't use codehaus api to generate the schema as we have a recursive JSON structure and I get StackOverflowError.
So, I tried using the fasterxml's jackson-module-jsonschema API to do this which works fine.
Sample output that I'm getting:
"Registration" : {
"type" : "object",
"id" : "urn:jsonschema:com:xyz.abc.Address",
}
I have two requirements:
Apart from "type" and "id", I also want to have a description attribute. I can add
@JsonPropertyDescriptionattribute, which would work, but then each property will have one annotation fromcodehausand another one from thefasterxmlpackage. Is there an equivalent annotation incodehauswhich can be used for this purpose?Is there a way to have just the un-qualified class name in the "id" attribute (only "Address" i.e. without the qualified object path "xyz.abc.Address" and without "urn:jsonschema") ?
Code for schema generation using fasterxml:
ObjectMapper mapper = new ObjectMapper();
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper);
JsonSchema schema = schemaGen.generateSchema(DashboardDef.class);
String generatedJsonSchema = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema);