2021年3月13日星期六

How to deserialize String Date into POJO?

I have the following JSON object:

{"name": "Foobar", "date": "2020-07-23 17:34:24"}  

that I would want to deserialize into a POJO, using Jackson.

To do this, I have the following class:

public class Person {        private String name;        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")      private OffsetDatetime date;    }  

It should work, but it doesn't, and I get an error message:

Jackson.databind.exc.InvalidDefinitionException: Cannot construct instance (no Creators, like default constructor, exist): no String-argument constructor/factory method to deserialize from String value ('2020-07-23 17:34:24')

I double checked the pattern and everything seems correct, but I am still getting this error. Anyone know why?

https://stackoverflow.com/questions/66620995/how-to-deserialize-string-date-into-pojo March 14, 2021 at 12:06PM

没有评论:

发表评论