Getting the JAXB exception like "Two classes have the same XML type name..."
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.
No comments:
Post a Comment