Posts

Showing posts with the label jaxb

java.lang.annotation.IncompleteAnnotationException: javax.xml.bind.annotation.XmlSchemaType missing element name

Hi The use case happened when i was trying to generate the java files from the wsdl using the CXF codegen maven plugin. The generated code  started failing with the above exception when tried to invoke via Eclipse. Note : the same wsdl worked in Soap UI. The generated code in SOAP UI using the WSIMPORT tool also worked. So the issue i figures out is related to the Jaxb in the project. So what i did is upgraded the Jaxb to this version                  <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.2</version> </dependency> It all started working. So this has something to do with the internal element generation of Jaxb and what happens is when a latest version is not found falls back to the jaxb version embedded in SDK leading to that error. Now i dont have a proof for that just an educated guess. :)

counts of IllegalAnnotationExceptions @javax.xml.bind.annotation.XmlElement annotation is found on two places; one would be suffice.

So this happen when you annotate the filed this way @XmlElement(name = "Country") private String country; Throws an Error as below @javax.xml.bind.annotation.XmlElement annotation is found on two places; one would be suffice. this problem is related to the following location: at @javax.xml.bind.annotation.XmlElement(nillable=false, name=Country, defaultValue= The easy fix is to move the annotation to the setter method @XmlElement(name = "Country") public void setCountry(String country) { this.country = country; } This Works Fine.

Jaxb not adding the @XMLRoot element.

There are those cases where you are trying to build an object Model from XSD and sees that there is no @XMLRootElement tag added to the root element in the stub and your unmarshelling starts failing. The    basic idea is that if we can statistically guarantee that a complex type won't be used by multiple different tag names, XJC put @XmlRootElement.  Try for the basic schema  http://www.w3schools.com/schema/  here. You see the root element gets generated. The issue happens when you have something like this <schema>   <element name = "Employee" type = "inc:CTEmployee" />   <complexType name = "CTEmployee" /> </schema>   You see the Employee element is not tagged with the @XMlRootElement in the stub. The Assumption that XJC does is  that  "your schema might be used by other schema's that XJC isn't compiling right now" . So basic fix is avoid doing the Complex type defined ou...