I use CXF to generate java code from a 3rd party wsdl (not maintained by us).
I have this two snippets working not as expected when marshalling to soap message.
XML:
<choice>
<sequence>
<element name="x" type="xt" nillable="true" minOccurs="0" />
</sequence>
<element name="y" type="yt"
nillable="true" minOccurs="0" />
</choice>
Java:
@XmlElement(name = "x", nillable = true)
protected Xx;
@XmlElement(name = "y", nillable = true)
protected Y y;
If I add x, but not y to the soap message (via code) then it looks like:
<x>123456782</x>
<y xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:nil="true" />
Why is it adding y to the soap message, while it's an optional element?
Something similar is happening with this snippet:
XML:
<attribute ref="z" use="required" fixed="XXX" />
Java:
@XmlAttribute(name = "z", namespace = "http://www.egem.nl/StUF/StUF0301",
required = true)
protected String z;
Here cxf (with schema validation on true) complains if I don't add the element via code.
If i turn of the schema validation then is not creating the element add all.
This element is required and has a fixed attribute, why isn't it creating it if i don't add it (via code)?
EDIT:
During development i realized that cxf was generating a .package-info.java file, which gave me trouble with namespaces. So I was searching for a way disable the generation of .package-info.java file. The solution for that was to put an extraarg to cxf codegen plugin: -xjc-npa in the pom file. That part in the pom looks like:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<configuration>
<defaultOptions>
<extraargs>
<extraarg>-xjc-npa</extraarg>
</extraargs>
</defaultOptions>
</configuration>
</plugin>
But to my surprise after re-generating the class files, was that all fixed elements are now constants. No more getters/setters generated. But unfortunately the problem with the choices remains.