Class OffsetDateTimeXmlAdapter


  • public class OffsetDateTimeXmlAdapter
    extends jakarta.xml.bind.annotation.adapters.XmlAdapter<String,​OffsetDateTime>
    JAXB adapter to convert between xs:dateTime and OffsetDateTime.

    If the adapter is used for unmarshalling (parsing XML to object) and there is no zone offset in the input data then it may be needed to extend this class and customize the getZoneOffsetForDateTime(java.time.LocalDateTime) method.

    • Constructor Detail

      • OffsetDateTimeXmlAdapter

        public OffsetDateTimeXmlAdapter()
    • Method Detail

      • unmarshal

        public final OffsetDateTime unmarshal​(String v)
        Converts from xs:dateTime format.

        A number of minor deviations from the standard are accepted while parsing. See DateTimeFormatterXSD.XSD_DATETIME_PARSER for more information.

        If there are more than 9 fractional digits on the second value then digits after the 9th digit will be ignored.

        Specified by:
        unmarshal in class jakarta.xml.bind.annotation.adapters.XmlAdapter<String,​OffsetDateTime>
      • marshal

        public final String marshal​(OffsetDateTime v)
        Converts to xs:dateTime format.
        Specified by:
        marshal in class jakarta.xml.bind.annotation.adapters.XmlAdapter<String,​OffsetDateTime>
      • getZoneOffsetForDateTime

        public ZoneOffset getZoneOffsetForDateTime​(LocalDateTime localDateTime)
        Gets ZoneOffset for a given LocalDateTime value. Sub-classes may override this.

        This method is needed because the XML Schema dateTime data type allows to leave out the offset. Therefore, when unmarshalling there may be no offset in the input data. If this is the case then this method will be called. In summary, the method is only called when unmarshalling and only when input data has no offset.

        The default implementation uses the the system's default zone id (from ZoneId.systemDefault()) and then finds the appropriate offset for that zone given a point in time of localDateTime.

        Parameters:
        localDateTime -
        Returns:
        offset to use when none is present in XML input data, never null