@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