Passing a date as JSON with Spring MVC and Jackson

后端 未结 2 1066
不思量自难忘°
不思量自难忘° 2020-12-21 10:59

I have a class with a java.util.Date field that I wish to pass from a client to a Spring controller. The controller returns HTTP 415 whenever I make the request. I have trie

相关标签:
2条回答
  • You have a serializer, but no deserializer, so it's only working one way...

    You also need:

     @JsonDeserialize(using = DateDeserializer.class)
    

    (with a DateDeserializer using the same date format).

    Why there isn't a single interface for both is a mystery to me :-)

    0 讨论(0)
  • 2020-12-21 11:29

    Instead of string, just pass date object from jsp as below.

    var date = new Date();
    var formData = {'date':date};
    

    And in the dto, make variable of type java.util.Date.

    0 讨论(0)
提交回复
热议问题