一:
response.setContentType("text/html;charset=utf-8");
ObjectMapper mapper=new ObjectMapper();
JsonFactory factory=mapper.getJsonFactory();
JsonGenerator jsonGenerator=factory.createJsonGenerator(response.getOutputStream());
Map map=new HashMap();
map.put("result", "1");
jsonGenerator.writeObject(map);
二:JsonObject json=new JsonObject();
json=JsonObject.fromJsonObject(object);
response.setContentType("text/html;charset=utf-8");
response.getWriter().write(json);
三:
spring MVC 3.X 支持註解,在須要序列化爲json輸出的類上增長@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
//@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
public class ActTerminalResultParam extends BaseFacadeAmountDepositTradeParam
implements Serializable{
注意:在類上注入此標誌時,返回此類時,會返回set屬性裏的值