I have an XSD Schema with the following element:
<xs:element name="FooResponse" type="commonTypes:Response" />
When I run the build (which has a xjc
goal for converting the schema to Java sources), a separate class file FooResponse.java
is not created (probably because it would be identical to Response.java
. Now, I know I can rewrite the schema like this:
<xs:element name="FooResponse">
<xs:complexType>
<xs:complexContent>
<xs:extension base="commonTypes:Request"/>
</xs:complexContent>
</xs:complexType>
</xs:element>
and get the result I'm looking for. However, the schema is automatically generated from a tool, and I'd rather not have to touch it manually. Is there a way to configure the plugin to create the source file in this situation?
I need to get both Response.java
and FooResponse.java
created, as there are other types unrelated to FooResponse
that need to inherit from that.
I tried creating an XJB binding file like this:
<jaxb:bindings version="2.0"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxb:bindings schemaLocation="my_schema.xsd" node="/xs:schema/xs:element[@name='FooResponse']">
<jaxb:class name="FooResponse"/>
</jaxb:bindings>
</jaxb:bindings>
This works in that I get both Response.java
and FooResponse.java
but the contents of FooResponse
is not exactly what I'd like:
public class FooResponse
extends JAXBElement<Response>
{
protected final static QName NAME = new QName("initech.com/c/m", "FooResponse");
public FooResponse(Response value) {
super(NAME, ((Class) Response.class), null, value);
}
public FooResponse() {
super(NAME, ((Class) Response.class), null, null);
}
}
This would be exactly what I want if I got it to extend Response
directly without wrapping it into a JAXBElement
.