无法使用jsonschema2pojo从json对象到java pojo生成日期时间字段?
我得到了以下json对象:无法使用jsonschema2pojo从json对象到java pojo生成日期时间字段?,java,json,Java,Json,我得到了以下json对象: { "period": { "startDate": "2016-09-01T14:39:13.884Z", "endDate": "2021-09-01T14:39:13.884Z" } 在我的maven插件配置中,我添加了 <plugin> <groupId>org.jsonschema2pojo</groupId> <artifactId>jsonschema2pojo-mav
{
"period": {
"startDate": "2016-09-01T14:39:13.884Z",
"endDate": "2021-09-01T14:39:13.884Z"
}
在我的maven插件配置中,我添加了
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>0.4.23</version>
<configuration>
<sourceType>json</sourceType>
</configuration>
<executions>
<execution>
<id>id</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
...
<dateTimeType>java.time.ZonedDateTime</dateTimeType>
</configuration>
</execution>
</executions>
</plugin>
字段的类型被识别为字符串。是否可以直接从具有正确日期时间类型的json对象生成?或者我必须使用json模式来实现这一点?这对我来说很有效,请参阅下面的maven插件设置。我能看到的唯一有意义的区别是,您使用json作为源代码,而我使用的是json模式文件。您是否可以尝试创建这样的架构文件:
{
"$schema": "http://json-schema.org/draft-03/schema",
"title": "My Title",
"type": "object",
"description": "The departure time info",
"properties": {
"scheduled": {
"type": "string",
"format": "date-time",
"required": true,
"description": "Scheduled time of departure."
},
.
.
.
}
这是我的maven插件配置:
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>0.4.32</version>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/schema/model</sourceDirectory>
<targetPackage>myPackage</targetPackage>
<useJodaDates>false</useJodaDates>
<useJodaLocalTimes>false</useJodaLocalTimes>
<useJodaLocalDates>false</useJodaLocalDates>
<includeJsr303Annotations>false</includeJsr303Annotations>
<includeAdditionalProperties>false</includeAdditionalProperties>
<dateTimeType>java.time.ZonedDateTime</dateTimeType>
<dateType>java.time.LocalDate</dateType>
<generateBuilders>true</generateBuilders>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
org.jsonschema2pojo
jsonschema2pojo maven插件
0.4.32
${basedir}/src/main/resources/schema/model
我的包裹
假的
假的
假的
假的
假的
java.time.zoneDateTime
java.time.LocalDate
真的
生成
这对我很有效,请参阅下面的maven插件设置。我能看到的唯一有意义的区别是,您使用json作为源代码,而我使用的是json模式文件。您是否可以尝试创建这样的架构文件:
{
"$schema": "http://json-schema.org/draft-03/schema",
"title": "My Title",
"type": "object",
"description": "The departure time info",
"properties": {
"scheduled": {
"type": "string",
"format": "date-time",
"required": true,
"description": "Scheduled time of departure."
},
.
.
.
}
这是我的maven插件配置:
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>0.4.32</version>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/schema/model</sourceDirectory>
<targetPackage>myPackage</targetPackage>
<useJodaDates>false</useJodaDates>
<useJodaLocalTimes>false</useJodaLocalTimes>
<useJodaLocalDates>false</useJodaLocalDates>
<includeJsr303Annotations>false</includeJsr303Annotations>
<includeAdditionalProperties>false</includeAdditionalProperties>
<dateTimeType>java.time.ZonedDateTime</dateTimeType>
<dateType>java.time.LocalDate</dateType>
<generateBuilders>true</generateBuilders>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
org.jsonschema2pojo
jsonschema2pojo maven插件
0.4.32
${basedir}/src/main/resources/schema/model
我的包裹
假的
假的
假的
假的
假的
java.time.zoneDateTime
java.time.LocalDate
真的
生成