• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

@XmlJavaTypeAdapter - the XmlAdapter never gets invoked

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic