Home » JSON » JsonSchemaToPojoGeneration

JsonSchemaToPojoGeneration

How to Generate POJOs from json schema File :
In this post I have described the simplest and best way to generate POJOs or model classes from a JSON schema file.
Step 1 :
Place the schema file in resource folder of the project.
Here I have kept the schema file in src/main/resources/schema folder.

Sample Schema File :
Employee.json

Step 2 :
Prepare pom.xml
a. Add “jsonschema2pojo-maven-plugin” plugin.
b. Provide json schema directory path in “sourceDirectory”.
c. Provide output directory path in “outputDirectory” where you want to generate the POJOs.
d. Provide the package name for the POJOs in “targetPackage”.
e. Add commons-lang jar to provide hashCode() and equals() implementation of POJOs.
f. Add jackson-annotations to provide jackson annotations for POJOs generated from JSON schema.
g. I have also used “generateBuilders” just to follow builder pattern in POJOs.If you do not require it ,do not use it.
pom.xml :

Step 3 :
Build the application using maven

Step 4 :
Output is generated now


Leave a comment

Your email address will not be published. Required fields are marked *

13 − ten =