I'm receiving a xsd file from a webservice. For one element the xsd defines a xs:date, but in fact the webservice returns a timestamp like 2019-10-19 12:00:00.

As I have no control over xsd, I'd like to write a jaxb mapping file that transforms the element type to a String instead of Date. So that I don't have to modify the xsd (as on the next webservice update, I'd have to remember my manual modification otherwise).

But how??

xsd:

<xs:complexType name="Person">
    <xs:element name="TicketTime" type=xs:date"/>
</xs:complexType>

jaxbbinding.xml:

<jaxb:bindings    
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    jaxb:version="2.1">

    <jaxb:bindings schemaLocation="xsd/my.xsd">
        <jaxb:bindings node="//xs:complexType[@name='Person']//xs:element[@name='TicketTime']">
           <!-- TOOD how to rewrite xs:date to xs:string? -->
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>

0 Answers