generateJsonSchema2Pojo Gradle Plugin, passing parameters?

591 views
Skip to first unread message

lda...@compcc.com

unread,
Oct 22, 2013, 11:48:08 AM10/22/13
to jsonschema...@googlegroups.com
Here is the scenario or desire:

I have a 4 different source locations and 4 different output locations (packages).   I would like to create a task to call generateJsonSchema2Pojo  4 times.  The desire is to be able to avoid the use of javaType for defining the package.  Is this possible or am I misunderstanding the proper usage pattern?  Is this a way to accomplish this...?

Example:
task createJsonSchema2Pojo << {
      generateJsonSchema2Pojo(source:files('mydir/json/form/'), targetPackage:'com.company.json.form', targetDirectory:file('src/java')).execute()
      generateJsonSchema2Pojo(source:files('mydir/json/response/shared'), targetPackage:'com.company.json.response.shared', targetDirectory:file('src/java')).execute()
      generateJsonSchema2Pojo(source:files('mydir/json/response/constructed'), targetPackage:'com.company.json.response.constructed', targetDirectory:file('src/java')).execute()
      generateJsonSchema2Pojo(source:files('mydir/json/response/'), targetPackage:'com.company.json.response', targetDirectory:file('src/java')).execute()
}

Cheers
Lee


Joe Littlejohn

unread,
Oct 22, 2013, 5:09:13 PM10/22/13
to jsonschema...@googlegroups.com
I think people have used this pattern to achieve what you need. I see no reason why this shouldn't work.

As of the 0.4.0 release what you need will happen automatically. The generator will recursively find files and add the name of any sub-directory found onto the end of the package name. So in future you should only need:

      generateJsonSchema2Pojo(source:files('mydir/json'), targetPackage:'com.company.json', targetDirectory:file('src/java')).execute()

Cheers



Notice: The information contained in this message or any attached document is confidential and intended only for individuals to whom it is addressed. If you got this message in error, please inform me immediately using one of the methods above. In some cases, I may ask you to return the documents at my expense. In general, please simply destroy the information at once. Any unauthorized use, distribution, or copying of this information is prohibited.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

lda...@compcc.com

unread,
Oct 22, 2013, 6:27:02 PM10/22/13
to jsonschema...@googlegroups.com
The usage in 0.4.0 looks exactly what we are after, which is great!  The obvious question, any guesses when this will be made available, even a SNAPSHOT type release with functionality quoted above?

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

Joe Littlejohn

unread,
Oct 23, 2013, 5:07:01 PM10/23/13
to jsonschema...@googlegroups.com
I've just built a snapshot that you can have a play with:


Let me know if you have any problems.

Cheers


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

lda...@compcc.com

unread,
Oct 23, 2013, 6:12:39 PM10/23/13
to jsonschema...@googlegroups.com
Excellent, will do!  Thank you!
To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema2pojo-users+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

lda...@compcc.com

unread,
Oct 29, 2013, 12:50:14 PM10/29/13
to jsonschema...@googlegroups.com
Hi Joe

I created a simplified example to showcase the issues I am seeing.   I am still seeing flat package structure, but am using javaType in the references, which I thought might address that.  Ideally I want to replicate the same structure\hierarchy found in the json directory.

Any help with this is much appreciated.   I know there is still some work that needs to be done around the $ref, but feel like I am missing something simple.


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

For more options, visit https://groups.google.com/groups/opt_out.





Notice: The information contained in this message or any attached document is confidential and intended only for individuals to whom it is addressed. If you got this message in error, please inform me immediately using one of the methods above. In some cases, I may ask you to return the documents at my expense. In general, please simply destroy the information at once. Any unauthorized use, distribution, or copying of this information is prohibited.

--
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-users+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Joe Littlejohn

unread,
Oct 29, 2013, 1:24:36 PM10/29/13
to jsonschema...@googlegroups.com
Hi Lee,

I haven't had a chance to run this but after a super quick look, I think you're applying javaType in the wrong place.

javaType gives a schema of type "object" a universal Java type name, it can't be applied to objects of type "array" (these already have a Java type name: java.util.List or java.util.Set). Now, if you want the _contents_ of the List or Set to have a specific Java type name, then you need to put the javaType inside the 'items' schema for that array. In your case, you must put this inside the referenced file (as $ref indicates that all other schema properties here should be ignored and the schema referenced by $ref should be used).

I hope the above helps. If this is still not clear I might have time to fork your code tomorrow evening and show you the changes I'm trying to describe.

Cheers



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

lda...@compcc.com

unread,
Oct 29, 2013, 7:28:43 PM10/29/13
to jsonschema...@googlegroups.com
Okay, I'll give that a shot. I'll wont be able to look at this until tomorrow, but will post up my findings.

Cheers
Lee

lda...@compcc.com

unread,
Jan 30, 2014, 11:20:06 AM1/30/14
to jsonschema...@googlegroups.com, lda...@compcc.com
Sorry for the multi-month follow up... had to switch gears.  Anyway tested this on 0.4.0 and it works great.  We did not have to go through the passing of parameters to select different directories as the gradle version tested in 0.4.0 walks the directories and recreates this package structure, which is the desired effect.  The only gotcha was the default setting for useDoubleNumbers was not true, so number type was converted to floats.  

Thanks again
Lee
Reply all
Reply to author
Forward
0 new messages