zoukankan      html  css  js  c++  java
  • FastJson过滤字段

    1、在对象对应字段前面加transient,表示该字段不用序列化,即在生成json的时候就不会包含该字段了。

    比如

    private transient  String name;  

    2、在对象响应字段前加注解,这样生成的json也不包含该字段。

    @JSONField(serialize=false)  
    private String name;  

    3.指定的字段才能显示出来

    SimplePropertyPreFilter filter = new SimplePropertyPreFilter(
    				MpBannerEntity.class, "title", "thumbUrl", "url");
    				JSONObject.toJSONString(要过滤的对象,
    								filter)

    4:过滤指定字段

    final String[] arr = new String[] { "ticketNo", "status", "updateTime",
    				"createTime" };
    		PropertyFilter propertyFilter = new PropertyFilter() {
    			public boolean apply(Object object, String name, Object value) {
    				for (String string : arr) {
    					if (name.equalsIgnoreCase(string)) {
    						return false;// 过滤掉
    					}
    				}
    				return true;// 不过滤
    			}
    		};

  • 相关阅读:
    poj1703
    poj 2385
    poj 3169 差分约束
    poj3723 最大权森林
    POJ3255 次短路
    图论算法----最小生成树
    给linux操作系统安装中文环境
    Windows下使用python
    pku3668 Game of Lines
    pku3670 Eating Together
  • 原文地址:https://www.cnblogs.com/zhousiwei/p/10625784.html
Copyright © 2011-2022 走看看