简体   繁体   中英

@XmlSchemaType for ObjectFactory method

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.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM