Class OffsetDateClassXmlAdapter


  • public class OffsetDateClassXmlAdapter
    extends jakarta.xml.bind.annotation.adapters.XmlAdapter<String,​OffsetDate>
    JAXB adapter to convert between xs:date and custom class OffsetDate.

    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 getZoneOffsetForDate(java.time.LocalDate) method.

    See Also:
    OffsetDateXmlAdapter
    • Constructor Detail

      • OffsetDateClassXmlAdapter

        public OffsetDateClassXmlAdapter()
    • Method Detail

      • marshal

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

        public ZoneOffset getZoneOffsetForDate​(LocalDate localDate)
        Gets ZoneOffset for a given LocalDate value. Sub-classes may override this.

        This method is needed because the XML Schema date 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 localDate + current-LocalTime.

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