Getting the JAXB exception like \"Two classes have the same XML type name...\",
Here is the exception details:
Exception in thread \
Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.
If you can modify the class you can simply add an @XmlType
annotation to one of the City
classes to change the corresponding XML schema type name.
package **com.common**;
@XmlType(name="city2")
public class City {
private String pinCode;
}
MOXy offers an external mapping document extension that can be used to apply JAXB metadata to a class that cannot be changed.
<?xml version="1.0"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="**com.common**">
<java-types>
<java-type name="City">
<xml-type name="city2"/>
</java-type>
</java-types>
</xml-bindings>
For More Information
1) we need to write binding file for only one City class or required to write all other 2 classes(i mean Address and another City)?
MOXy's external mapping document can used to augment or completely replace (see: http://blog.bdoughan.com/2011/09/mapping-objects-to-multiple-xml-schemas.html) the metadata on a class. If the only change you need to make is to one of the City
classes then you don't need to include the others.
2) In binding file you had considered only class name, not required to take properties defined in City(i mean pinCode)?
MOXy like any JAXB implementation applies a default mapping to all classes. You only need to provide metadata for where you want the mapping behaviour to differ from the default.
3)We need to opt for MOXy for this?
JAXB does not have a standard external mapping document. The one I have described is a MOXy extension. If you are using the JAXB RI you could check out the integration with Annox.