03-28-2014 03:32 PM
res.addHeader("Accept", "application/json");
res.addHeader("Content-type", "application/json; charset=UTF-8");
res.getWriter().write(mapper.writeValueAsString(myObject));
@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;
}
}
B b = new B();
b.setX("Whatever");
mapper = new ObjectMapper();
System.out.println("JSON:"+mapper.writeValueAsString(b));
JSON:{"x":"Whatever"}
JSON:{"@class":"org.xxx.alfresco.web.B","x":"Whatever"}
03-28-2014 11:26 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.