Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Getting the JAXB exception like “Two classes have the same XML type name…”

1044791Oct 2 2013

Getting the JAXB exception like "Two classes have the same XML type name...",

Here is the exception details:

Exception in thread "main" com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions Two classes have the same XML type name "city". Use @XmlType.name and @XmlType.namespace to assign different names to them. this problem is related to the following location: at com.model.City at public com.model.City com.model.Address.getCurrentCity() at com.model.Address this problem is related to the following location: at com.common.City at public com.common.City com.model.Address.getPreviousCity() at com.model.Address

at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source) at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source) at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at javax.xml.bind.ContextFinder.newInstance(Unknown Source) at javax.xml.bind.ContextFinder.find(Unknown Source) at javax.xml.bind.JAXBContext.newInstance(Unknown Source) at javax.xml.bind.JAXBContext.newInstance(Unknown Source) at com.PojoToXSD.main(PojoToXSD.java:17)

I took the example like:

package com.model; ---->this package contains 'Address' class and 'City' class

public class Address {

private String areaName; private City currentCity; private com.common.City previousCity;

}

package com.model;

public class City {

private String cityName;

}

Another city class in "com.common" package.

package com.common;

public class City {

private String pinCode;

}

We need to create XSDs and needs to do the Marshalling and unmarshalling with the existing code in our project(like as above example code), code does not have any annotations like "@XmlRootElement/@XmlType" and we can not able to change the source code.

I would like to know is there any solution to fix the above issue or any other ways to create XSDs and marshaling/unmarshalling(like MOXy..etc)?

It would be great if i can get the solution from any one....May thanks in advance.

Thanks,

Satya.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 30 2013
Added on Oct 2 2013
0 comments
13,232 views