Java 使用Jackson和spring boot序列化嵌套的Joda DateTime

Java 使用Jackson和spring boot序列化嵌套的Joda DateTime,java,json,spring-mvc,jackson,jodatime,Java,Json,Spring Mvc,Jackson,Jodatime,我正在使用Jackson和Sprint Boot编写一个API。此API返回包含Joda DateTime对象的对象(PipelineDetailsResponse),以及包含DateTime对象的对象列表(List) 但是,当我调用API时,我看到startTimestamp和endTimestamp字段被正确地序列化为unix时间戳,但是CommitDetails“时间戳字段不是。我需要做些特别的事吗 http localhost:8080/pipelines/FastLane_testGe

我正在使用Jackson和Sprint Boot编写一个API。此API返回包含Joda DateTime对象的对象(
PipelineDetailsResponse
),以及包含DateTime对象的对象列表(
List

但是,当我调用API时,我看到
startTimestamp
endTimestamp
字段被正确地序列化为unix时间戳,但是
CommitDetails
时间戳
字段不是。我需要做些特别的事吗

http localhost:8080/pipelines/FastLane_testGetDetails_100 Authorization:"Bearer ${JWT_TOKEN}"
HTTP/1.1 200 OK
// headers tri

{
    "approvalDetails": null,
    "author": null,
    "buildNumber": 100,
    "commitDetailList": [
        {
            "author": "dalvizu",
            "message": "Some changes",
            "sha1": "1234",
            "timestamp": {
                "iChronology": {
                    "iBase": {
                        "iMinDaysInFirstWeek": 4.0
                    }
                },
                "iMillis": 1487807156248.0
            }
        }
    ],
    "commitUrl": null,
    "deployUrl": null,
    "endTimestamp": 1487720756247,
    "serviceName": "testGetDetails",
    "startTimestamp": 1487717156247,
    "uniqueId": "FastLane_testGetDetails_100"
}
在pom.xml中,我添加了jackson数据类型joda jar:

    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-joda</artifactId>
        <version>2.8.6</version>
    </dependency>
以下是my@RestController中的API方法:

@RequestMapping(value = "/pipelines/{uniqueId}", method = RequestMethod.GET)
public ResponseEntity get(@PathVariable String uniqueId)
{
    PipelineDetailsResponse response = service.getPipelineDetails(uniqueId);
    return ResponseEntity.ok(response);
}

有什么想法吗?

您的
commitDetail
响应具有具有不同属性的对象结构,但没有日期时间值。您试图从timestamp对象检索哪个属性值?我希望我的响应在
PipelineDetailsResponse.startTimeStamp
PipelineDetailsResponse.commitDetailsList.get(0).timestamp
中包含一致的JSON返回值-它们是相同的joda DateTime类型。理想的unix时间戳值。你能分享设置时间戳的代码吗?哦,我是个白痴。我在cassandra中将列表保存为JSON,但没有用Jackson保存它我认为你解决了这个问题了吗?
public class CommitDetail
{
    private String author;

    private String sha1;

    private String message;

    private DateTime timestamp;
@RequestMapping(value = "/pipelines/{uniqueId}", method = RequestMethod.GET)
public ResponseEntity get(@PathVariable String uniqueId)
{
    PipelineDetailsResponse response = service.getPipelineDetails(uniqueId);
    return ResponseEntity.ok(response);
}