I have a weird situation where the getter in a class returns a primitive int type, and the setter takes a Integer class.
When jaxb unmarshals an element to this class, it cannot find the setter it is looking for:
public class Foo {
int bar;
public int getBar() {
return this.bar;
}
public void setBar(Integer bar) {
this.bar = bar.intValue();
}
}
I have tried adding:
@XmlElement ( type = java.lang.Integer.class, name = "bar" )
to the getter (and the setter), to change the type of the field in schema, but that does not help.
During unmarshalling I get this error: The property has a getter “public int com.example.getBar()” but no setter. For unmarshalling, please define setters.
I can’t modify the class, as in, I can’t change bar to an Integer or add a new setter with primitive type, but I can add annotations.
You can solve this issue by configuring JAXB to use field access. This is done via the
@XmlAccessorTypeannotation:For More Information