我有一个使用字段LocalDate的表单,该字段从通过Jackson映射的表单接收值。
JSON是:

Tue Jun 27 2017 00:00:00 GMT+0200 (ora legale Europa occidentale)


我的LocalDate变量是2017-06-26
这是我的pojo:

public class BookingForm {
    private Integer building;
    private Integer city;
    private LocalDate date;
    private String description;
    private LocalTime endTime;
    private List<Integer> externalUsers;
    private List<Integer> internalUsers;
    private String name;
    private Room room;
    private LocalTime startTime;
    private List<ExternalUser> newExternalUsers;
    //get and set method


我为JDK8引入了Jackson:

<!-- Jackson dependencies -->
<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-hibernate5</artifactId>
    <version>${jacksondatatype.version}</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jdk8</artifactId>
    <version>${jacksondatatype.version}</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jsr310</artifactId>
    <version>${jacksonjsr310.version}</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.module</groupId>
    <artifactId>jackson-module-parameter-names</artifactId>
    <version>${jacksondatatype.version}</version>
</dependency>


Date代替LocalDate都可以正常工作。
时区还是其他问题?

更新:
这是我的Spring配置:

public MappingJackson2HttpMessageConverter jacksonMessageConverter(){
    MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();

    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    //authomatic registration
    mapper.findAndRegisterModules();

    messageConverter.setObjectMapper(mapper);
    return messageConverter;

}


可以在这里配置吗?

最佳答案

我认为您的Jackson已设置为使用格林尼治标准时间,而您的BookingForm可能正在使用其他类似BST的功能,这导致了

关于java - 引导日期选择器和LocalDate之间的一日类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44762751/

10-12 05:49