利用jackson转成json字符串(ssh中)

时间:2023-12-06 12:08:32
 public String getJsonString(Object o){
ObjectMapper om = new ObjectMapper();
StringWriter sw = new StringWriter();
try{
JsonGenerator jg = new JsonFactory().createJsonGenerator(ws);
om.writeValue(jg,o);
jg.close();
}catch(){}
return ws.toString() ;
} public void writeJson(Object o) {
String json = getJsonString(o);
try{
ServletActionContext.getResponse().getWriter().write(json);
}catch(){}
}