- 问题描述:通过JsonFormat注解来实现时间的格式化
@JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime timestamp;
...
new ObjectMapper().writeValueAsString(obj);
"timestamp": {
"year": 2022,
"month": "FEBRUARY",
"nano": 326000000,
"monthValue": 2,
"dayOfMonth": 24,
"hour": 11,
"minute": 40,
"second": 58,
"dayOfWeek": "THURSDAY",
"dayOfYear": 55,
"chronology": {
"calendarType": "iso8601",
"id": "ISO"
}
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime timestamp;