time parsing error

error details

Caused by: java.time.format.DateTimeParseException: Text '2023-11-20 11:00:00' could not be parsed at index 10
   at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
   at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
   at java.time.LocalDateTime.parse(LocalDateTime.java:492)
   at com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer.deserialize(LocalDateTimeDeserializer.java:100)
   ... 103 common frames omitted

The parameter passed by the front end is "2023-11-20 11:00:00"

The backend is java, and java uses LocalDateTime to receive

@ApiModelProperty(value = "signing time")
private LocalDateTime signTime;

The reason for the error is that no pattern is specified, and it is used by default, so the default format will be used, that is: DateTimeFormatter.ISO_LOCAL_DATE_TIME, which is similar to this: 2011-12-03T10:15:30.

Solution, add annotation

   @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")

Reference document: Solve Jackson parsing error "Cannot deserialize value of type `java.time.LocalDateTime` from String … could not be parsed at index 10" — Freedom House Blog

Guess you like

Origin blog.csdn.net/wangwenzhe222/article/details/130481469