jsonschema2pojo generates two java classes for each json schema

1,210 views
Skip to first unread message

iobe...@gmail.com

unread,
Oct 2, 2014, 11:38:27 AM10/2/14
to jsonschema...@googlegroups.com
Hello.
I'm using this utility to generate pojos from json schemas.
Here's what the schema looks like:

userUpdateSchema.json:
{
   
"$schema": "http://json-schema.org/draft-04/schema#",
   
"id": "http://jsonschema.net#",
   
"type": "object",
   
"additionalProperties": false,
   
"properties": {
       
"userConfig": {
           
"id": "#userConfig",
           
"type": "object",
           
"additionalProperties": false,
           
"properties": {
               
"code": {
                   
"id": "#code",
                   
"type": "string",
                   
"additionalProperties": false,
                   
"pattern": "^[0-9]*$",
                   
"minLength": 4,
                   
"maxLength": 4
               
},
               
"id": {
                   
"id": "#id",
                   
"type": "integer",
                   
"additionalProperties": false
               
},
               
"name": {
                   
"id": "#name",
                   
"type": "string",
                   
"additionalProperties": false,
                   
"maxLength": 16
               
}
           
},
           
"required": [
               
"code",
               
"id",
               
"name"
           
]
       
}
   
},
   
"required": [
       
"userConfig"
   
]
}


Here's the entry for this plugin in my pom:

<plugin>
               
<groupId>org.jsonschema2pojo</groupId>
               
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
               
<version>0.4.5</version>
               
<configuration>
                   
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
                   
<outputDirectory>${basedir}/src/main/resources/java</outputDirectory>
                   
<targetPackage>com.example.types</targetPackage>
                   
<sourceType>jsonschema</sourceType>
                   
<includeJsr303Annotations>true</includeJsr303Annotations>
                   
<usePrimitives>true</usePrimitives>
               
</configuration>
               
<executions>
                   
<execution>
                       
<goals>
                           
<goal>generate</goal>
                       
</goals>
                   
</execution>
               
</executions>
       
</plugin>


When I run mvn:package the utility creates two java classes for this schema: UserConfig.java and UserUpdateSchema.java

How do I prevent it from generating UserUpdateSchema.java?

UserConfig.java is the correct one - for the json object descibed in the json schema above.


Thanks

- Joe

Joe Littlejohn

unread,
Oct 2, 2014, 11:43:26 AM10/2/14
to jsonschema...@googlegroups.com
Hi Joe,

UserUpdateSchema is an object that has one property: userConfig. If you only want the UserConfig class generated, then the schema you should use as input would look like:

--
You received this message because you are subscribed to the Google Groups "jsonschema2pojo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema2pojo-...@googlegroups.com.
Visit this group at http://groups.google.com/group/jsonschema2pojo-users.
For more options, visit https://groups.google.com/d/optout.

Joe Berger

unread,
Oct 2, 2014, 12:04:26 PM10/2/14
to jsonschema...@googlegroups.com
Thanks for the prompt reply! You're awesome!
That makes sense.
You received this message because you are subscribed to a topic in the Google Groups "jsonschema2pojo-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jsonschema2pojo-users/QzFE_HFcyOc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jsonschema2pojo-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages