@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)


一:
  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屬性里的值


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM