After switching plugin jsonschema2pojo-maven-plugin (version: 0.5.1) and creating json schema with type = string and format = date-time, generated java class has java.util.Date field type instead of java.lang.String

649 views
Skip to first unread message

dev-b...@veeroute.com

unread,
Oct 20, 2017, 3:55:28 AM10/20/17
to jsonschema2pojo-users
Hello.

After switching plugin jsonschema2pojo-maven-plugin (version: 0.5.1) and creating json schema with type = string and format = date-time and after execution of mvn generate-sources,
generated java class has java.util.Date field type instead of java.lang.String.
Actually, It works good when using type=string and format=date.

My plugin:

<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>0.5.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<sourceDirectory><PATH></sourceDirectory>
<outputDirectory><PATH></outputDirectory>
<targetPackage><PACKAGE></targetPackage>
</configuration>
</execution>
</executions>
</plugin>

When I add <dateTimeType>java.lang.String</dateTimeType>, then it works like a charm:

<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>0.5.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
                <dateTimeType>java.lang.String</dateTimeType>
<sourceDirectory><PATH></sourceDirectory>
<outputDirectory><PATH></outputDirectory>
<targetPackage><PACKAGE></targetPackage>
</configuration>
</execution>
</executions>
</plugin>

But in https://joelittlejohn.github.io/jsonschema2pojo/site/0.5.1/generate-mojo.html#dateTimeType, there is a record below:

dateTimeType:

What type to use instead of string when adding string type fields of format date-time to generated Java types.
  • Typejava.lang.String
  • Since0.4.22
  • RequiredNo
  • Expression${jsonschema2pojo.dateTimeType}
So, default type which should be used in generated classes is java.lang.String and why it is not used?

Please check and fix it in next releases if there is some bug.

Thank you.

Joe Littlejohn

unread,
Oct 20, 2017, 11:32:44 AM10/20/17
to jsonschema...@googlegroups.com
Hi

The *type* of the parameter dateTimeType is java.lang.String, this is not the default value. The Maven docs are showing what kind of value to provide.

The default has been java.util.Date for as long as I can remember. This has never defaulted to java.lang.String that I know of. What version were you using before you upgraded, that used java.lang.String by default?

--
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.
Visit this group at https://groups.google.com/group/jsonschema2pojo-users.
For more options, visit https://groups.google.com/d/optout.

dev-b...@veeroute.com

unread,
Oct 24, 2017, 9:13:34 AM10/24/17
to jsonschema2pojo-users
Hi

I used version: 0.5.1
Never upgraded. It is my very first version of plugin.
When I add type = string and format = date-time to my Json Schema, then plugin generates POJO with java.lang.String field which is not clear for me because when I add type = string and format = date then plugin generates java.util.Date.

Thanks!

пятница, 20 октября 2017 г., 19:32:44 UTC+4 пользователь Joe Littlejohn написал:

Joe Littlejohn

unread,
Oct 24, 2017, 9:16:32 AM10/24/17
to jsonschema...@googlegroups.com
Are you adding <dateTimeType>java.lang.String</dateTimeType> to your configuration? If you are doing this, then that is the reason you see the String type.

By default, format:date-time = java.util.Date, format:date = String.

On 20 October 2017 at 08:55, <dev-b...@veeroute.com> wrote:

--

dev-b...@veeroute.com

unread,
Oct 25, 2017, 2:56:18 AM10/25/17
to jsonschema2pojo-users
Yes. I am adding <dateTimeType>java.lang.String</dateTimeType>. I thought that format:date-time = String, format:date = String by default and that is why I did not add <dateTimeType>java.lang.String</dateTimeType> into configuration at first. After that I did and it worked. 

But now you are saying that format:date-time = java.util.Date, format:date = String by  default. It would be nice to have some defaults in docs. But it is ok.

Thanks :)

вторник, 24 октября 2017 г., 17:16:32 UTC+4 пользователь Joe Littlejohn написал:
Reply all
Reply to author
Forward
0 new messages