简体   繁体   English

杰克逊时间戳解析字符串

[英]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: 我从postgresql json_build_object函数收到了这个日期字符串2017-12-16T14:06:01.49291并且我在对象中使用了以下内容:

@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. 并且有效,但是我仍然认为有更好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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