I have following code which is returning Foo
@GET
@Produces (MediaType.APPLICATION_XML)
public Foo getXML (){
System.out.println ("getXML Request");
Foo f = new Foo();
d.setA("test");
d.setB("xyxyx");
return f;
}
and my Foo Class is
@XmlRootElement
public class Foo{
public void setA(String a) {
this.a = a;
}
public void setB(String b) {
this.b = b;
}
public String getB (){
return b;
}
public String getA (){
return a;
}
@XmlAttribute(name="atrribB")
private String b;
@XmlElement(name="elementA")
private String a;
}
While doing so, I got error on Foo that Class has two properties of the same name "A" and same goes for B.
When i deleted getters method for both of these properties, everything was fine. am i suppose not to create getter setters and leave fields has public ?
You need to either annotate the get methods
or specify
@XmlAccessorType(XmlAccessType.FIELD).For More Information