I've got a XSD describing some sequences of complex types e.g.
<xs:complexType name="Catalog">
<xs:sequence>
<xs:element name="Category" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="ParentCategoryIDRef"/>
<xs:element type="xs:string" name="Method"/>
</xs:sequence>
<xs:complexType>
</xs:element>
</xs:sequence>
<xs:complexType>
Now when I use JaxBs XJC to convert this into Java classes it will generate me a java.util.List
in my Catalog
class for the field and getter/setter of Category
.
However, what I need for using it in an Axis2 webservice using java2wsdl are Arrays like Category[]
.
I'm a bit familiar with JaxB bindings and already tried specifying the collection type using:
<jaxb:property collectionType="Category[]"/>
which resulted in invalid code, because it was still using a java.util.List
, but with a constructor new Category[]<Category>
.
Of course I can always edit the generated code after generation, but this would cause problems when I try to re-generate it.
What I've got now is:
public class Catalog {
@XmlElement(name = "Category")
protected List<Category> category;
}
What I want is:
public class Catalog {
@XmlElement(name = "Category")
protected Category[] category;
}
Any ideas? I'm currently using XJC 2.2.6 with Axis2 1.6.2.
I think you need to use the javaType tag:
<xs:complexType name="catalog">
<xs:sequence>
<xs:element name="category" type="ns:Category" >
<xs:annotation>
<xs:appinfo>
<jxb:javaType name="Category[]"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
Generates the following class:
public class Catalog {
@XmlElement(required = true, type = Category.class)
protected Category[] category;
public Category[] getCategory() {
return category;
}
public void setCategory(Category[] value) {
this.category = value;
}
}
(Using the org.apache.cxf cxf-xjc-plugin 2.6.2 maven plugin)
You will also need the definition of Category in your XSD...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With