Can JAXB handle java.time objects?

Basil Bourque picture Basil Bourque · Jun 16, 2014 · Viewed 12.1k times · Source

I know JAXB (Java Architecture for XML Binding) can marshal/unmarshal java.util.Date objects as seen in this answer by Blaise Doughan.

But what about the new java.time package objects in Java 8, such as ZonedDateTime? Has JAXB been updated to handle this newly built-in data type?

Answer

bdoughan picture bdoughan · Jun 16, 2014

In Java SE 8, JAXB has not been updated yet to support the java.time types.

Indeed, there is an issue related to this in the reference implementation.

You need to create and use an XmlAdapter to handle those types. Use an approach similar to that done with Joda-Time as described in this posting, JAXB and Joda-Time: Dates and Times.

You may be able to use this implementation of adapters for java.time.