Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.model.annotation.AnnotationReader

As per link: Why has AnnotationReader been removed from JAXB reference implementation?, you need to simply use below maven dependencies: <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-impl</artifactId> <version>2.2.11</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-core</artifactId> <version>2.2.11</version> </dependency> You need to refactor code a bit. Also looks like you’ve not created same name fields of model class, it should be like below: Person.java … Read more

Marshalling a List of objects implementing a common interface, with JaxB

For this scenario I would recommend the use of @XmlElements. @XmlElements is used to represent the XML schema concept of choice: http://bdoughan.blogspot.com/2010/10/jaxb-and-xsd-choice-xmlelements.html Here is how it would look for your example: @XmlElements({ @XmlElement(name=”girl”, type=Girl.class), @XmlElement(name=”boy”, type=Boy.class) }) @XmlElementWrapper public List<Person> getPeople() { return people; } @XmlElementRef corresponds to the concept of substitution groups in XML … Read more

JaxbRepresentation gives error “doesnt contain ObjectFactory.class or jaxb.index”

In my case I was able to resolve this by adding a file called “jaxb.index” in the same package folder as the JAXB annotated class. In that file list the simple, non-qualified names of the annotated classes. For example, my file /MyProject/src/main/java/com/example/services/types/jaxb.index is simply one line (since I have only one JAXB typed class): ServerDiagContent … 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.

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

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)