0

我有一个 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;
...

谢谢!

4

1 回答 1

0
<dependency>
  <groupId>com.fasterxml.jackson.datatype</groupId>
  <artifactId>jackson-datatype-joda</artifactId>
  <version>2.8.7</version>
</dependency>

添加上面的maven依赖。

于 2019-04-16T02:45:54.260 回答