iduetxe/jsonschema2pojo


Generates Java types from JSON Schema (or example JSON) and annotates those types for data-binding with Jackson 1.x or 2.x, Gson, etc http://www.jsonschema2pojo.org

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    
	dependencies {
		implementation 'com.github.iduetxe:jsonschema2pojo:jsonschema2pojo-0.4.13'
	}
	dependencies {
		implementation("com.github.iduetxe:jsonschema2pojo:jsonschema2pojo-0.4.13")
	}
	<dependency>
	    <groupId>com.github.iduetxe</groupId>
	    <artifactId>jsonschema2pojo</artifactId>
	    <version>jsonschema2pojo-0.4.13</version>
	</dependency>

                            
    libraryDependencies += "com.github.iduetxe" % "jsonschema2pojo" % "jsonschema2pojo-0.4.13"
        
        

                            
    :dependencies [[com.github.iduetxe/jsonschema2pojo "jsonschema2pojo-0.4.13"]]
        
        

Readme


jsonschema2pojo Build Status

jsonschema2pojo generates Java types from JSON Schema (or example JSON) and can annotate those types for data-binding with Jackson 1.x, Jackson 2.x or Gson.

This code is a fork from https://github.com/joelittlejohn/jsonschema2pojo and is based on https://github.com/lsubramanya/jsonschema2pojo

This code improves the property 'deserializationClassProperty' adding to generated pojos the annotation @JsonSubTypes.

Example:

{
    "type" : "object",
    "deserializationClassProperty":{
        "propertyName":"discriminatorValue",
        "children":
            [
                {
                    "className": "ChildArraySchema1",
                    "value": "OBJ_1"
                },
                {
                    "className": "ChildArraySchema2",
                    "value": "OBJ_2"
                }
            ]
    },
    "properties" : {
        "propertyOfParent" : {
            "type" : "string"
        },
        "deserializationClassProperty":{
            "type" : "string"
        }
    }
}

The result will be:

@Generated("org.jsonschema2pojo")
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "discriminatorValue")
@JsonSubTypes({
    @JsonSubTypes.Type(value = ChildArraySchema1.class, name = "OBJ_1"),
    @JsonSubTypes.Type(value = ChildArraySchema2.class, name = "OBJ_2")
})
@JsonPropertyOrder({
    "discriminatorValue"
})
public class ValidationRQRDTO {

    @JsonProperty("discriminatorValue")
    private String discriminatorValue;
    ....
}