Hi,
Could someone explain the strange behaviour of the JAXB 2.0 RI with the following case?
@XmlType
@XmlRootElement
public class Foo {
@XmlElement
protected String foo = null;
public Foo() {
super();
}
public String getFoo() {
return foo;
}
public void setFoo(String foo) {
this.foo = foo;
}
}
When marshalling, I get the following error:
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Class has two properties of the same name "foo"
this problem is related to the following location:
at public java.lang.String test.Foo.getFoo()
at test.Foo
this problem is related to the following location:
at protected java.lang.String test.Foo.foo
at test.Foo
Changing the visibility of the field has no effects.
Transfering the @XMLElement from the field to the getter solves the problem.
This is just personnal consideration, but I always prefer to annotate fields rather than properties (accessors) when I have the choice, the resulting code looks cleaner for me.
Some of the JAXB annotations (like @XMLElement) are intended to be used with both fields and properties, so... what is the problem?
Thanks
-Jerome