I am trying to implement
@XmlJavaTypeAdapter to marshal/unmarshal
java.time.LocalDateTime from JSON to
Java and visa versa.
Here is a brief example what I have besed my implementation on.
https://www.jorgenringen.com/2015/05/23/jsr310-java-time-api-with-jax-rs/#comment-471
However, when I implement what I think is exactly as suggested, my
XmlAdapter (LocalDateAdapter) (unmarshal & marshal) class never gets called.
When I do a
GET from my RestController, my java.time.LocalDateTime gets formatted in JSON as follows:
I always get the following error when doing a
POST:
at [Source: java.io.PushbackInputStream@1fd4d283; line: 1, column: 8] (through reference chain: com.jobs.spring.domain.Employee["joiningDate"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class java.time.LocalDateTime] from String value ('2016-07-04 12:24:19'); no single-String constructor/factory method
This is my model class's entry:
My LocalDateAdapter.
This is my Spring config:
and
RestController
I have also tried package-info.java with no success.
I write a
unit test that calls the
XmlAdapter (LocalDateTimeAdapter) successfully.
But I am a little confused how to configure the equivalent to my runtime. i.e. How to wire this in Spring for it to get invoked when the RESTful service is called. Does the JAXBContext need to be registered somehow?
Is there any other configuration I need to do to make it aware of the LocalDateAdapter class?
(I am using Java 8 and Spring 4.3.1)
Thank you