我有一个API,我使用Jackson和Sprint Boot写作。此API返回包含Joda DateTime对象的对象(PipelineDetailsResponse
),以及包含DateTime对象的对象列表(List<CommitDetail>
)。
但是,当我调用API时,我看到startTimestamp
和endTimestamp
字段已正确序列化为unix时间戳,但CommitDetails
&#39; timestamp
字段不是。我需要做一些特别的事吗?
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-datatype-joda jar:
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.8.6</version>
</dependency>
我要归还的对象:
public class PipelineDetailsResponse
{
private String uniqueId;
private String deployUrl;
private String commitUrl;
private String serviceName;
private List<CommitDetail> commitDetailList = new ArrayList<>();
private String approvalDetails;
private String author;
private int buildNumber;
private DateTime startTimestamp;
private DateTime endTimestamp;
这引用了一个CommitDetail列表,它还包含一个DateTime字段:
public class CommitDetail
{
private String author;
private String sha1;
private String message;
private DateTime timestamp;
以下是我的@RestController中的API方法:
@RequestMapping(value = "/pipelines/{uniqueId}", method = RequestMethod.GET)
public ResponseEntity get(@PathVariable String uniqueId)
{
PipelineDetailsResponse response = service.getPipelineDetails(uniqueId);
return ResponseEntity.ok(response);
}
有什么想法吗?