我在使用 Spring Boot 和 Jackson-databind 2.5.2 将 Joda DateTime 从 java 序列化和反序列化为 json 并再次返回时遇到问题。我的 pom.xml 看起来像这样。
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.2.1.RELEASE</version>
</dependency>
当我序列化 DateTime 对象时,我得到一个表示 DateTime 的整数。实际上不是我所期望的,但是很好。但是当我去保存我的对象时,我收到以下错误......
Failed to convert property value of type 'java.lang.String' to required type 'org.joda.time.DateTime' for property 'endTime';
nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type org.joda.time.DateTime for value '1428600998511'
由于某种原因,它将其序列化为整数,然后将其反序列化,就好像它是字符串一样,但事实并非如此。我还尝试在调用其余服务之前设置 endTime = new Date(intValue) ,并且尝试将“Tue Apr 28 2015 00:00:00 GMT-0700 (PDT)”之类的字符串转换为 DateTime 也失败。
我究竟做错了什么?
UPDATE:
这是我得到的 JSONand我尝试立即发回。
{
id: 4,
username: "",
name: "eau",
email: "aoue",
verbatimLocation: null,
latitude: null,
longitude: null,
startTime:null,
endTime: 1429034332312,
description: "ueoa",
media: [ ],
timeSubmitted: 1428600998000,
status: null,
submissionid: null
}