I have an object that I\'d like to serve in JSON as a RESTful resource. I have Jersey\'s JSON POJO support turned on like so (in web.xml):
Why are you using final fields? I'm using jersey and i have some JAXB objects/pojos and all i had to do was simply annotate my resource method with @Produces("application/json") and it works out of the box. I didn't have to mess with the web.xml. Just make sure your pojos are annotated correctly.
Here is a simple pojo
package test;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class SampleJaxbObject {
private String field1;
private Integer field2;
private String field3;
public String getField1() {
return field1;
}
public void setField1(String field1) {
this.field1 = field1;
}
public Integer getField2() {
return field2;
}
public void setField2(Integer field2) {
this.field2 = field2;
}
public String getField3() {
return field3;
}
public void setField3(String field3) {
this.field3 = field3;
}
}