maven plugin not working for JSON object as input

917 views
Skip to first unread message

anushre...@gmail.com

unread,
Mar 27, 2014, 6:01:28 PM3/27/14
to jsonschema...@googlegroups.com
Hi Joe,

I have a fairly complex JSON object and need to generate the java classes for that. I tried using your online tool for that and it works fine.
But, as a project requirement I will have to use the maven plugin only, I tried using the same but it wont generate any classes for json object.

I read in your documentation that default value for source is json schema (creating the json schema for my json object is not feasible for me as well) 
your documentation says json data will be supported as well. 

Can you please tell me how can modify this default value to support json instead of jsonschema?

sourceTypeString0.3.3The type of input documents that will be read

Supported values:

  • jsonschema (schema documents, containing formal rules that describe the structure of json data)
  • json (documents that represent an example of the kind of json data that the generated Java types will be mapped to)

Default value isjsonschema.

Your quickest reply will be really helpful as I am totally blocked by this. 
Thanks in advance. :)


Joe Littlejohn

unread,
Mar 27, 2014, 6:17:01 PM3/27/14
to jsonschema...@googlegroups.com, anushre...@gmail.com
Are you familiar with Maven?

When you want to specify a value for a configuration property you can do so like:

<configuration>
    <sourceType>json</sourceType>
</configuration>


The default is 'jsonschema' but if you set the value to 'json' then the plugin will expect JSON input.

Am I missing something here?

anushre...@gmail.com

unread,
Mar 27, 2014, 6:36:12 PM3/27/14
to jsonschema...@googlegroups.com, anushre...@gmail.com
Thanks for quick reply joe.
I am very much new to maven, but I have already tried changing the configuration to change the sourceType. It did not work. 
Here is how it looks like.. m I missing out something?

<plugin>

     <groupId>org.jsonschema2pojo</groupId>

     <artifactId>jsonschema2pojo-maven-plugin</artifactId>

     <version>0.4.1</version>

    <configuration>

           <sourceType>json</sourceType>

           <sourceDirectory>src/main/resources</sourceDirectory>

          <targetPackage>com.example.wrappers</targetPackage>

    </configuration>

   <executions>

   <execution>

         <goals>

         <goal>generate</goal>

         </goals>

     </execution>

</executions>

</plugin>

Joe Littlejohn

unread,
Mar 27, 2014, 6:38:57 PM3/27/14
to jsonschema...@googlegroups.com
This looks correct, what json files do you have in /src/main/resources and what output do you see in /target/java-gen?

The website uses this same version of the library (0.4.1), if JSON works on http://jsonschema2pojo.org then it should work here.


--
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.

anushre...@gmail.com

unread,
Mar 27, 2014, 6:48:44 PM3/27/14
to jsonschema...@googlegroups.com
I am using a Twitter Json object as a part of my project. the same object is workin through the website but not using maven. 
Also, even after changing the configuration, the maven plugin seems to generate classes for the  address schema(one on ur site as an example) as an input.

Looks like, its not taking the changed configuration for sourceType json 
To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema2pojo-users+unsub...@googlegroups.com.

Joe Littlejohn

unread,
Mar 27, 2014, 6:55:33 PM3/27/14
to jsonschema...@googlegroups.com
> Also, even after changing the configuration, the maven plugin seems to
> generate classes for the  address schema(one on ur site as an example) as an input.

This would suggest to me that you have multiple pom.xml files and that you are changing the wrong file. Whatever configuration is being used, it's not the same configuration that you are editing.

Do you have anyone working with you that can give you some Maven help? Or maybe you could browse through your project and make sure you're building the right thing. There is certainly no possible way that the Maven plugin would generate classes associated with the address schema unless the project you are executing specifies this schema.

As I say, the website is using the same version of the same tool to generate json (so if it works on the site, it will work in the Maven plugin). I think this is a problem is either elsewhere in the pom.xml (do you have to configurations for the same plugin?) or you are not building the same project that you are editing.

Sorry I can't offer any solution here other than to re-check your files and maybe ask another engineer to do the same.


To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema2pojo-...@googlegroups.com.

Anushree Gupte

unread,
Mar 27, 2014, 7:41:11 PM3/27/14
to jsonschema...@googlegroups.com
Thanks Joe, it worked! :)

I did couple of things. 
As u said, I had another file called dependency-reduced-pom.xml along with pom.xml. I changed the configurations in other file too.
And then gave .json extension to my input file (dont kno if this actually matters!)
But thanks a lot for your help throughout...really appreciate it! :)


Thanks,
Anu


--
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/D2RvlKasHFk/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