Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用jsonschema2pojo从json对象到java pojo生成日期时间字段?_Java_Json - Fatal编程技术网

无法使用jsonschema2pojo从json对象到java pojo生成日期时间字段?

无法使用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

我得到了以下json对象:

{
  "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
真的
生成