Search code examples
datetimexsdwsdlmapping

Map from date/dateTime in XSD to dateTime in WSDL


I'm working in a project which exposes some webservices with SOAP 1.1. I have a XSD file to define some entities which has something like

<xs:complexType name="someComplexType">
    <xs:sequence>
        <!-- also tried with xs:dateTime -->
        <xs:element name="startDate" type="xs:date" minOccurs="1" />
        <xs:element ... />
    </xs:sequence>
</xs:complexType>

With Eclipse I can generate the classes and I have something like

public class SomeComplexType {
     // some XML annotations
     private XMLGregorianCalendar startDate;
}

The problem is that when I check the URL in the browser (http://example.com/myService?wsdl) to see the generated WSDL I see something like

<xs:complexType name="someComplexType">
    <xs:sequence>
        <xs:element form="qualified" name="startDate"
            type="xs:anySimpleType" />
        <xs:element ... />
    </xs:sequence>
</xs:complexType>

But I need to map from date or dateTime in XSD to dateTime in WSDL. How can I accomplish that?

NOTE: I need to touch "as less as posible" another configuration but the XSD file (solve it from there is ideal)

I've been searching around another posts from here and from JBOSS developers but all of them suggest some extra config files, or add some configuration in maven plugins, which is not desirable for me.

Any contribution is welcomed. Thanks in advance for your answers


Solution

  • After seeing another JAXB classes I found a way to solve this problem. Unfortunately, it isn't automatically built by Eclipse but you have to do some boilerplate.

    First of all, you have to serialize by hand every generated class, as they are passible to be streamed in a given moment. It's also recomended, as the JAXB classes are POJO's in the end (or at least is my point of view), it's useful to override hashCode(), equals() and toString().

    Lastly, and to solve the problem, you need to add @javax.xml.bind.annotation.XmlSchemaType(name = "dateTime") to every XMLGregorianCalendar property. With that the generated WSDL will have those properties as xs:dateTime.

    Hope that helps somebody. Best regards