我有一个spring rest api(实际上是spring项目顶部的apache wicket rest api),它返回一个对象,该对象的属性为joda LocalDate。
一切都很好,除了joda LocalDate / LocalTime / DateTime ...它们以以下格式返回:
"createdDate": {
"year": 2019,
"dayOfMonth": 15,
"dayOfWeek": 1,
"era": 1,
"weekOfWeekyear": 16,
"secondOfMinute": 21,
"millisOfSecond": 455,
"dayOfYear": 105,
"millisOfDay": 72861455,
"yearOfCentury": 19,
"weekyear": 2019,
"minuteOfHour": 14,
"secondOfDay": 72861,
"yearOfEra": 2019,
"centuryOfEra": 20,
"minuteOfDay": 1214,
"monthOfYear": 4,
"hourOfDay": 20,
"zone": {
"fixed": false,
"uncachedZone": {
"cachable": true,
"fixed": false,
"id": "Australia/Perth"
},
"id": "Australia/Perth"
},
"millis": 1555330461455,
"chronology": {
"zone": {
"fixed": false,
"uncachedZone": {
"cachable": true,
"fixed": false,
"id": "Australia/Perth"
},
"id": "Australia/Perth"
}
},
"equalNow": false,
"afterNow": false,
"beforeNow": true
},
我希望该值的格式为yyyy-MM-dd'T'HH:mm:ss
。
我尝试在上述字段中使用JsonFormat
注释,但是没有运气。
...
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
@Field("createdDateS")
private DateTime createdDate;
...
谢谢!
答案 0 :(得分:0)
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.8.7</version>
</dependency>
添加以上Maven依赖项。