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.
Answer from Edgar Domingues on Stack OverflowVideos
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.
EDIT: as pointed out by commenters, module is being deprecated, not maintained. So, Caveat Emptor etc
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.
If you have already POJO you can use Instancio library with your POJO for data setup.
You can generate fake java-objects and then map them to JSON.
POJOs
If you already have the POJOs matching the schema, then we can skip this step. If no, to generate a POJO from the schema, for example, can be used this library: jsonschema2pojo.
Fake objects
Generating of objects with fake data can be done with a special library, some of them are listed here:
- easy-random
- podam
- java-faker
Generating JSON
It's prettry simple and can be done with Jackson:
ObjectMapper objectMapper = new ObjectMapper();
ObjectWriter prettyPrinter = objectMapper.writerWithDefaultPrettyPrinter();
String json = prettyPrinter.writeValueAsString(yourFakeObject);
You can try the JSON Schema Faker. It will take a schema and generate/output a JSON object that will validate against the schema.
Code available on githubcom
My team and I have created an online tool that allows you to parse JSON schema and generate an array of JSON data that complies to the schema. You can save it as .json file and parse it to your app with a Java parser.
The tool is called Mock turtle - https://mockturtle.net .