├── jsonSchemaGenerator
├── target
│ └── classes
│ │ ├── input.json
│ │ ├── META-INF
│ │ ├── MANIFEST.MF
│ │ └── maven
│ │ │ └── com.quinnox
│ │ │ └── jsonSchemaGenerator
│ │ │ ├── pom.properties
│ │ │ └── pom.xml
│ │ └── com
│ │ └── quinnox
│ │ ├── util
│ │ ├── Input.class
│ │ ├── JsonToPojoConverter.class
│ │ └── JsonToPojoConverter$1.class
│ │ └── generator
│ │ ├── pojo
│ │ └── Student.class
│ │ └── JsonSchemaGeneratorV1.class
├── src
│ └── main
│ │ ├── resource
│ │ ├── input.json
│ │ └── com
│ │ │ └── quinnox
│ │ │ └── util
│ │ │ └── Input.java
│ │ └── java
│ │ └── com
│ │ └── quinnox
│ │ ├── generator
│ │ ├── pojo
│ │ │ └── Student.java
│ │ └── JsonSchemaGeneratorV1.java
│ │ └── util
│ │ └── JsonToPojoConverter.java
├── .settings
│ ├── org.eclipse.m2e.core.prefs
│ └── org.eclipse.jdt.core.prefs
├── .project
├── .classpath
└── pom.xml
└── README.md
/jsonSchemaGenerator/target/classes/input.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mohit",
3 | "age": 24
4 | }
5 |
--------------------------------------------------------------------------------
/jsonSchemaGenerator/src/main/resource/input.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mohit",
3 | "age": 24
4 | }
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # json2pojowithschemaGen
2 | separate classes for json to pojo conversion and from pojo classes to json schema
3 |
--------------------------------------------------------------------------------
/jsonSchemaGenerator/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/jsonSchemaGenerator/target/classes/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Built-By: MohitK
3 | Build-Jdk: 1.8.0_231
4 | Created-By: Maven Integration for Eclipse
5 |
6 |
--------------------------------------------------------------------------------
/jsonSchemaGenerator/target/classes/com/quinnox/util/Input.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohit6350/json2pojowithschemaGen/HEAD/jsonSchemaGenerator/target/classes/com/quinnox/util/Input.class
--------------------------------------------------------------------------------
/jsonSchemaGenerator/target/classes/com/quinnox/generator/pojo/Student.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohit6350/json2pojowithschemaGen/HEAD/jsonSchemaGenerator/target/classes/com/quinnox/generator/pojo/Student.class
--------------------------------------------------------------------------------
/jsonSchemaGenerator/target/classes/com/quinnox/util/JsonToPojoConverter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohit6350/json2pojowithschemaGen/HEAD/jsonSchemaGenerator/target/classes/com/quinnox/util/JsonToPojoConverter.class
--------------------------------------------------------------------------------
/jsonSchemaGenerator/target/classes/com/quinnox/util/JsonToPojoConverter$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohit6350/json2pojowithschemaGen/HEAD/jsonSchemaGenerator/target/classes/com/quinnox/util/JsonToPojoConverter$1.class
--------------------------------------------------------------------------------
/jsonSchemaGenerator/target/classes/com/quinnox/generator/JsonSchemaGeneratorV1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohit6350/json2pojowithschemaGen/HEAD/jsonSchemaGenerator/target/classes/com/quinnox/generator/JsonSchemaGeneratorV1.class
--------------------------------------------------------------------------------
/jsonSchemaGenerator/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
3 | org.eclipse.jdt.core.compiler.compliance=1.5
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.5
6 |
--------------------------------------------------------------------------------
/jsonSchemaGenerator/target/classes/META-INF/maven/com.quinnox/jsonSchemaGenerator/pom.properties:
--------------------------------------------------------------------------------
1 | #Generated by Maven Integration for Eclipse
2 | #Wed Dec 11 12:03:04 IST 2019
3 | version=1.0-SNAPSHOT
4 | groupId=com.quinnox
5 | m2e.projectName=jsonSchemaGenerator
6 | m2e.projectLocation=D\:\\MIKE\\CTC\\jsonSchemaGenerator\\jsonSchemaGenerator
7 | artifactId=jsonSchemaGenerator
8 |
--------------------------------------------------------------------------------
/jsonSchemaGenerator/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | jsonSchemaGenerator
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.m2e.core.maven2Nature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/jsonSchemaGenerator/src/main/java/com/quinnox/generator/pojo/Student.java:
--------------------------------------------------------------------------------
1 | package com.quinnox.generator.pojo;
2 |
3 | import java.util.Arrays;
4 |
5 | public class Student {
6 |
7 | private String name;
8 | private int roll;
9 | private String[] subjects;
10 |
11 | public String getName() {
12 | return name;
13 | }
14 |
15 | public void setName(String name) {
16 | this.name = name;
17 | }
18 |
19 | public int getRoll() {
20 | return roll;
21 | }
22 |
23 | public void setRoll(int roll) {
24 | this.roll = roll;
25 | }
26 |
27 | public String[] getSubjects() {
28 | return subjects;
29 | }
30 |
31 | public void setSubjects(String[] subjects) {
32 | this.subjects = subjects;
33 | }
34 |
35 | @Override
36 | public String toString() {
37 | return "Student [name=" + name + ", roll=" + roll + ", subjects=" + Arrays.toString(subjects) + "]";
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/jsonSchemaGenerator/src/main/java/com/quinnox/generator/JsonSchemaGeneratorV1.java:
--------------------------------------------------------------------------------
1 | package com.quinnox.generator;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 |
6 | import org.codehaus.jackson.JsonNode;
7 | import org.codehaus.jackson.map.SerializationConfig;
8 |
9 | import com.quinnox.util.Input;
10 |
11 | public class JsonSchemaGeneratorV1 {
12 |
13 | public static void main(String[] args) throws IOException {
14 | System.out.println(JsonSchemaGeneratorV1.getJsonSchema(Input.class));
15 | }
16 |
17 | public static String getJsonSchema(Class clazz) throws IOException {
18 |
19 | org.codehaus.jackson.map.ObjectMapper objectMapper = new org.codehaus.jackson.map.ObjectMapper();
20 | objectMapper.configure(SerializationConfig.Feature.WRITE_ENUMS_USING_TO_STRING, true);
21 | org.codehaus.jackson.schema.JsonSchema jsonSchema = objectMapper.generateJsonSchema(clazz);
22 | return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/jsonSchemaGenerator/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/jsonSchemaGenerator/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | com.quinnox
6 | jsonSchemaGenerator
7 | jar
8 | 1.0-SNAPSHOT
9 | jsonSchemaGenerator
10 | http://maven.apache.org
11 |
12 |
13 | junit
14 | junit
15 | 3.8.1
16 | test
17 |
18 |
19 | com.fasterxml.jackson.core
20 | jackson-core
21 | 2.7.1
22 |
23 |
24 | com.fasterxml.jackson.core
25 | jackson-databind
26 | 2.7.1
27 |
28 |
29 | com.fasterxml.jackson.core
30 | jackson-annotations
31 | 2.7.1
32 |
33 |
34 | com.fasterxml.jackson.module
35 | jackson-module-jsonSchema
36 | 2.1.0
37 |
38 |
39 | org.jsonschema2pojo
40 | jsonschema2pojo-core
41 | 0.4.35
42 |
43 |
44 | org.jsonschema2pojo
45 | jsonschema2pojo-core
46 | 0.4.35
47 |
48 |
49 | com.kjetland
50 | mbknor-jackson-jsonschema_2.12
51 | [---LATEST VERSION---]
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/jsonSchemaGenerator/target/classes/META-INF/maven/com.quinnox/jsonSchemaGenerator/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | com.quinnox
6 | jsonSchemaGenerator
7 | jar
8 | 1.0-SNAPSHOT
9 | jsonSchemaGenerator
10 | http://maven.apache.org
11 |
12 |
13 | junit
14 | junit
15 | 3.8.1
16 | test
17 |
18 |
19 | com.fasterxml.jackson.core
20 | jackson-core
21 | 2.7.1
22 |
23 |
24 | com.fasterxml.jackson.core
25 | jackson-databind
26 | 2.7.1
27 |
28 |
29 | com.fasterxml.jackson.core
30 | jackson-annotations
31 | 2.7.1
32 |
33 |
34 | com.fasterxml.jackson.module
35 | jackson-module-jsonSchema
36 | 2.1.0
37 |
38 |
39 | org.jsonschema2pojo
40 | jsonschema2pojo-core
41 | 0.4.35
42 |
43 |
44 | org.jsonschema2pojo
45 | jsonschema2pojo-core
46 | 0.4.35
47 |
48 |
49 | com.kjetland
50 | mbknor-jackson-jsonschema_2.12
51 | [---LATEST VERSION---]
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/jsonSchemaGenerator/src/main/java/com/quinnox/util/JsonToPojoConverter.java:
--------------------------------------------------------------------------------
1 | package com.quinnox.util;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.net.URL;
6 |
7 | import org.jsonschema2pojo.DefaultGenerationConfig;
8 | import org.jsonschema2pojo.GenerationConfig;
9 | import org.jsonschema2pojo.Jackson2Annotator;
10 | import org.jsonschema2pojo.SchemaGenerator;
11 | import org.jsonschema2pojo.SchemaMapper;
12 | import org.jsonschema2pojo.SchemaStore;
13 | import org.jsonschema2pojo.SourceType;
14 | import org.jsonschema2pojo.rules.RuleFactory;
15 |
16 | import com.quinnox.generator.JsonSchemaGeneratorV1;
17 | import com.sun.codemodel.JCodeModel;
18 | import com.sun.codemodel.JType;
19 |
20 | public class JsonToPojoConverter {
21 | public static void main(String[] args) {
22 | String packageName = "com.quinnox.util";
23 | File inputJson = new File(JsonToPojoConverter.class.getClassLoader().getResource("input.json").getPath());
24 | File outputPojoDirectory = new File("src/main/resource");
25 | outputPojoDirectory.mkdirs();
26 | try {
27 | new JsonToPojoConverter().convert2JSON(inputJson.toURI().toURL(), outputPojoDirectory,packageName,
28 | inputJson.getName().replace(".json", ""));
29 | } catch (IOException e) {
30 | // TODO Auto-generated catch block
31 | System.out.println("Encountered issue while converting to pojo: " + e.getMessage());
32 | e.printStackTrace();
33 | }
34 | }
35 |
36 | public void convert2JSON(URL inputJson, File outputPojoDirectory, String packageName, String className)
37 | throws IOException {
38 | JCodeModel codeModel = new JCodeModel();
39 | URL source = inputJson;
40 | GenerationConfig config = new DefaultGenerationConfig() {
41 | @Override
42 | public boolean isGenerateBuilders() { // set config option by overriding method
43 | return true;
44 | }
45 |
46 | public SourceType getSourceType() {
47 | return SourceType.JSON;
48 | }
49 | };
50 | SchemaMapper mapper = new SchemaMapper(
51 | new RuleFactory(config, new Jackson2Annotator(config), new SchemaStore()), new SchemaGenerator());
52 | JType jType = mapper.generate(codeModel, className, packageName, source);
53 | codeModel.build(outputPojoDirectory);
54 | JsonSchemaGeneratorV1 gen = new JsonSchemaGeneratorV1();
55 | //System.err.println(gen.getJsonSchema(Input.class));
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/jsonSchemaGenerator/src/main/resource/com/quinnox/util/Input.java:
--------------------------------------------------------------------------------
1 |
2 | package com.quinnox.util;
3 |
4 | import java.util.HashMap;
5 | import java.util.Map;
6 | import com.fasterxml.jackson.annotation.JsonAnyGetter;
7 | import com.fasterxml.jackson.annotation.JsonAnySetter;
8 | import com.fasterxml.jackson.annotation.JsonIgnore;
9 | import com.fasterxml.jackson.annotation.JsonInclude;
10 | import com.fasterxml.jackson.annotation.JsonProperty;
11 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
12 | import org.apache.commons.lang.builder.EqualsBuilder;
13 | import org.apache.commons.lang.builder.HashCodeBuilder;
14 | import org.apache.commons.lang.builder.ToStringBuilder;
15 |
16 | @JsonInclude(JsonInclude.Include.NON_NULL)
17 | @JsonPropertyOrder({
18 | "name",
19 | "age"
20 | })
21 | public class Input {
22 |
23 | @JsonProperty("name")
24 | private String name;
25 | @JsonProperty("age")
26 | private Integer age;
27 | @JsonIgnore
28 | private Map additionalProperties = new HashMap();
29 |
30 | @JsonProperty("name")
31 | public String getName() {
32 | return name;
33 | }
34 |
35 | @JsonProperty("name")
36 | public void setName(String name) {
37 | this.name = name;
38 | }
39 |
40 | public Input withName(String name) {
41 | this.name = name;
42 | return this;
43 | }
44 |
45 | @JsonProperty("age")
46 | public Integer getAge() {
47 | return age;
48 | }
49 |
50 | @JsonProperty("age")
51 | public void setAge(Integer age) {
52 | this.age = age;
53 | }
54 |
55 | public Input withAge(Integer age) {
56 | this.age = age;
57 | return this;
58 | }
59 |
60 | @Override
61 | public String toString() {
62 | return ToStringBuilder.reflectionToString(this);
63 | }
64 |
65 | @JsonAnyGetter
66 | public Map getAdditionalProperties() {
67 | return this.additionalProperties;
68 | }
69 |
70 | @JsonAnySetter
71 | public void setAdditionalProperty(String name, Object value) {
72 | this.additionalProperties.put(name, value);
73 | }
74 |
75 | public Input withAdditionalProperty(String name, Object value) {
76 | this.additionalProperties.put(name, value);
77 | return this;
78 | }
79 |
80 | @Override
81 | public int hashCode() {
82 | return new HashCodeBuilder().append(name).append(age).append(additionalProperties).toHashCode();
83 | }
84 |
85 | @Override
86 | public boolean equals(Object other) {
87 | if (other == this) {
88 | return true;
89 | }
90 | if ((other instanceof Input) == false) {
91 | return false;
92 | }
93 | Input rhs = ((Input) other);
94 | return new EqualsBuilder().append(name, rhs.name).append(age, rhs.age).append(additionalProperties, rhs.additionalProperties).isEquals();
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------