Jaxb, Class has two properties of the same name Jaxb, Class has two properties of the same name xml xml

Jaxb, Class has two properties of the same name


I also faced problem like this and i set this.

@XmlRootElement(name="yourRootElementName")@XmlAccessorType(XmlAccessType.FIELD)

This will work 100%


You didn't specified what JAXB-IMPL version are you using, but once I had the same problem (with jaxb-impl 2.0.5) and solved it using the annotation at the getter level instead of using it at the member level.


I've also seen some similiar issues like this.

I think, it's because of the place where we use the "@XMLElement" annotation in the (bean) class.

And I think, the JAXB (annotation processor) considers the member field & getter method of the same field element as different properties, when we use the @XMLElement annotation at the field level and throws the IllegalAnnotationExceptions exception.

Exception Message :

Class has two properties of the same name "timeSeries"

At Getter Method :

    at public java.util.List testjaxp.ModeleREP.getTimeSeries()

At Member Field :

    at protected java.util.List testjaxp.ModeleREP.timeSeries

Solution :Instead of using @XmlElement in the field, use it in the getter method.