Class DateAdapter


public final class DateAdapter extends XmlAdapter<XMLGregorianCalendar,Date>
JAXB adapter wrapping the date value (as milliseconds elapsed since January 1st, 1970) in a XMLGregorianCalendar for the xs:date type. Hours, minutes and seconds are discarded.

Using this adapter is equivalent to apply the following annotation on a Date field:

The main difference is that this adapter will take in account the timezone declared using the XML.TIMEZONE property.
Since:
0.4
Version:
0.4
See Also:
  • Constructor Details

    • DateAdapter

      public DateAdapter()
      Empty constructor for JAXB only.
  • Method Details

    • unmarshal

      public Date unmarshal(XMLGregorianCalendar value)
      Converts a date read from a XML stream to the object which will contain the value. JAXB calls automatically this method at unmarshalling time.
      Specified by:
      unmarshal in class XmlAdapter<XMLGregorianCalendar,Date>
      Parameters:
      value - the XML date, or null.
      Returns:
      the java.util date, or null.
    • marshal

      public XMLGregorianCalendar marshal(Date value)
      Converts the date to the object to be marshalled in a XML file or stream. JAXB calls automatically this method at marshalling time.
      Specified by:
      marshal in class XmlAdapter<XMLGregorianCalendar,Date>
      Parameters:
      value - the java.util date value, or null.
      Returns:
      the XML date, or null.