I have an object that I am trying to serialize in a webscript. I have bee doing this forever now:
res.addHeader("Accept", "application/json");
res.addHeader("Content-type", "application/json; charset=UTF-8");
res.getWriter().write(mapper.writeValueAsString(myObject));
and everything is fine.I have now added annotations to my beans. I have an abstract superclass that I use @JsonTypeInfo, and a @JsonIgnore for some field. However, I do NOT see the @class property that should have been added, and the field marked ignore is showing up.I then added this as a test.
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class")
public abstract class A {
}
public class B extends A {
private String x;
public String getX() {
return x;
}
public void setX(String x) {
this.x = x;
}
}
and in a webscript I do this:
B b = new B();
b.setX("Whatever");
mapper = new ObjectMapper();
System.out.println("JSON:"+mapper.writeValueAsString(b));
and my output is:
JSON:{"x":"Whatever"}
when I run it in a static main() I get the correct output:
JSON:{"@class":"org.xxx.alfresco.web.B","x":"Whatever"}
Is there some special thing I need to do to turn on annotaions for Alfresco webscripts?