Class OffsetTimeXmlAdapter


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

    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 getZoneOffsetForTime(java.time.LocalTime) method.

    • Constructor Detail

      • OffsetTimeXmlAdapter

        public OffsetTimeXmlAdapter()
    • Method Detail

      • unmarshal

        public final OffsetTime unmarshal​(String v)
        Converts from xs:time format.

        A number of minor deviations from the standard are accepted while parsing. See DateTimeFormatterXSD.XSD_TIME_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,​OffsetTime>
      • marshal

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

        public ZoneOffset getZoneOffsetForTime​(LocalTime localTime)
        Gets ZoneOffset for a given LocalTime value. Sub-classes may override this.

        This method is needed because the XML Schema time 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 current-LocalDate + localTime.

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