@XmlSchemaType for ObjectFactory method

952 views Asked by At

I have a XSD choice, both of them being of type javax.xml.datatype.XMLGregorianCalendar. As recommended, I have used the ObjectFactory and JAXBElement to differentiate between the two choices.

@XmlElementDecl(namespace = "http://me.com/1.0/api", name="timestamp")
JAXBElement<XMLGregorianCalendar> createTimestamp(XMLGregorianCalendar timestamp) {
    return new JAXBElement<XMLGregorianCalendar>(_timestamp_QNAME, XMLGregorianCalendar.class, null, timestamp);
}

I now want to change the type that appears in the autogenerated WSDL to 'dateTime' instead of xs:anySimpleType.

It looks like the @XmlSchemaType annotation isn't supported on the ObjectFactory method and Package level @XmlSchameType tags aren't able to modify the types generated here either.

@javax.xml.bind.annotation.XmlSchemaType(name="dateTime", type=javax.xml.datatype.XMLGregorianCalendar.class)
package my.example.api;

This still generated xs:anySimpleType in this particular case.

I cannot use EclipseLink in my project.

1

There are 1 answers

1
bdoughan On

Instead of doing:

@XmlElementRefs({
    @XmlElementRef(name="foo", type=JAXBElement.class),
    @XmlElementRef(name="bar", type=JAXBElement.class)
})
public JAXBElement<XMLGregorianCalendar> getFooOrBar() {
    return fooOrBar;
}

You will need to have a separate property for each element to get the behaviour you are looking for. Since by default JAXB doesn't marshal properties with a null value you will still be able to produce the XML you are looking for.

public XMLGregorianCalendar getFoo() {
    return foo;
}

@XmlSchemaType(name="time")
public XMLGregorianCalendar getFoo() {
    return foo;
}