I have a POJO class:
public class Stock {
int id;
String name;
Date date;
}
Are there any annotations or development framework/API that can convert POJO to JSON schema like below:
{"id":
{
"type" : "int"
},
"name":{
"type" : "string"
}
"date":{
"type" : "Date"
}
}
And also I can expand the schema to add information like "Required" : "Yes"
, description for each field, etc., by specifying some annotations or configurations on POJO and can generate JSON Schema like below:
{"id":
{
"type" : "int",
"Required" : "Yes",
"format" : "id must not be greater than 99999",
"description" : "id of the stock"
},
"name":{
"type" : "string",
"Required" : "Yes",
"format" : "name must not be empty and must be 15-30 characters length",
"description" : "name of the stock"
}
"date":{
"type" : "Date",
"Required" : "Yes",
"format" : "must be in EST format",
"description" : "filing date of the stock"
}
}
One such tool is Jackson JSON Schema module:
https://github.com/FasterXML/jackson-module-jsonSchema
which uses Jackson databind's POJO introspection to traverse POJO properties, taking into account Jackson annotations, and produces a JSON Schema object, which may then be serialized as JSON or used for other purposes.
Java JSON Schema Generator: https://github.com/victools/jsonschema-generator
Creates JSON Schema (Draft 6, Draft 7 or Draft 2019-09) from Java classes using Jackson.
Use JJschema. It can generate draft 4 compliant JSON schemas. Refer this post http://wilddiary.com/generate-json-schema-from-java-class/ for details.
Though Jackson Json Schema module can too generate schema but it can, as of today, only generate draft 3 compliant schemas only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With