IllegalAnnotationException: Two classes have the same XML type name

I found the cause of my problem. This problem occurs because JAX-WS generates a class for each method and the class name is constructed by concatenating methodName + “Response”. In my case, the newly generated class by JAX-WS will have the same name as my response object. Example: @Stateless @WebService() public class AccountWS { @WebMethod() …

Read more

Remove ns2 as default namespace prefix

All you need 2 do is when you open a new package select create package info in the package info add the following annotation or change it as needed @javax.xml.bind.annotation.XmlSchema(namespace = “http://www.sitemaps.org/schemas/sitemap/0.9”, elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, xmlns = { @javax.xml.bind.annotation.XmlNs(namespaceURI = “http://www.sitemaps.org/schemas/sitemap/0.9”, prefix = “”) }) This will remove the ns2 prefix

JAXB generating JAXBElement instead of String

What I had to do is to wrap jaxb:globalBindings with another jaxb:bindings. <jaxb:bindings version=”2.0″ xmlns:jaxb=”http://java.sun.com/xml/ns/jaxb”> <jaxb:bindings> <jaxb:globalBindings generateElementProperty=”false”/> </jaxb:bindings> </jaxb:bindings> Now everything is working, there is no JAXBElement<String> generated anymore.

convert xml to java object using jaxb (unmarshal)

Tests On the Tests class we will add an @XmlRootElement annotation. Doing this will let your JAXB implementation know that when a document starts with this element that it should instantiate this class. JAXB is configuration by exception, this means you only need to add annotations where your mapping differs from the default. Since the …

Read more

How to serialize and de-serialize objects using JAXB?

It would be nice if you included some code that explains your problem. JAXB 101 says you should place the right annotations, then you can serialize and deserialize correctly. You should properly annotate your classes with @XmlRootElement, @XmlElement, @XmlAttribute, etc For example: @XmlRootElement(name=”student”) @XmlAccessorType(XmlAccessType.NONE) class Student { @XmlElement(name=”name”) private String name; @XmlElement(name=”age”) private int age; …

Read more

How to generate CDATA block using JAXB?

Note: I’m the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group. If you are using MOXy as your JAXB provider then you can leverage the @XmlCDATA extension: package blog.cdata; import javax.xml.bind.annotation.XmlRootElement; import org.eclipse.persistence.oxm.annotations.XmlCDATA; @XmlRootElement(name=”c”) public class Customer { private String bio; @XmlCDATA public void setBio(String bio) { this.bio = bio; …

Read more

What is an .episode file..?

Note: I’m the EclipseLink JAXB (MOXy) lead and a member of the JAXB 2 (JSR-222) expert group. A .episode file is generated by the XJC (XML Schema to Java) compiler. It is a schema bindings that associates schema types with existing classes. It is useful when you have one XML schema that is imported by …

Read more

JAXB IllegalAnnotationException is thrown during parsing XML

The exception is due to your JAXB (JSR-222) implementation believing that there are two things mapped with the same name (a field and a property). There are a couple of options for your use case: OPTION #1 – Annotate the Field with @XmlAccessorType(XmlAccessType.FIELD) If you want to annotation the field then you should specify @XmlAccessorType(XmlAccessType.FIELD) …

Read more

@XMLRootElement versus @XmlType

The difference between XmlRootElement and XmlType is a matter of scoping. Remember this annotation is merely dictating the creation of the schema used to generate your XML. The XmlRootElement denotes a global element (with an anonymous or schema type): <xs:element name=foo type=”bar”> </xs:element> <– schema type while the XmlType is used to denote a local …

Read more