How to format date field in JSON POST request to insert into SQL database?

I need to send a POST request with the following JSON body:

{  "date": "2020-08-21" } 

The date field has java.sql.Date type. This request results in an error which says that it could not deserialize the given string "2020-08-21" to sql.Date. If I change the JSON by adding some kind of time:

{  "date": "2020-08-21 00:00:00" } 

It works fine. However, I would like to be able to send only Date values without the time, and be able to convert it to sql.Date. Any ideas on how to work around this? I would really not like to use a String for date and then map it to Date. Are there better ways to do this?

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.