Ritesh Waghela
Ritesh Waghela

Reputation: 3727

Jackson datetime not getting serialized. bad request

I am using spring framework and working on REST web services. One of my rest service insert/updates the date time value stored in one of the column of the my MySQL database table. The type I am using is datetime. My JSON request looks like:

                 {
                    "userId": "1",
                     "dateOfBirth": "1987-02-06 15:53:12",      

                 }

Spring has been configured to use Jackson as message converter. dateOfBirth field in java object is of type java.util.Date. Problem I am facing is when I hit the rest service with the above json request, the request becomes Bad request. I think it is related to date time conversion, jackson is not able to covert it to a date object. Any help will be appreciated.

Upvotes: 0

Views: 954

Answers (1)

indybee
indybee

Reputation: 1736

Can try creating customer serializer/deserailzer by extending JsonSerializer and JsonDeserializer classes, and then annotate the date field with them, see these 2 posts:

How to deserialize JS date using Jackson?

Spring 3.1 JSON date format

Upvotes: 1

Related Questions