简体   繁体   中英

Jackson Timestamp parse string

I received this date string 2017-12-16T14:06:01.49291 from postgresql json_build_object function and i used the following in my object:

@JsonProperty("creation_date")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss.SSS")
private Timestamp creationDate;

when parsing i received the following exception:

Exception in thread "main" com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.sql.Timestamp` from String "2017-12-16T14:06:01.49291": expected format "yyyy-MM-dd HH:mm:ss.SSS"

Any idea on how to parse such string inside jackson

I used this pattern

 @JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ss.SSS")

and it worked, but I still think there is a better solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM