fastjson比较重要的几点

/*
* 第一种:在对象响应字段前加注解,这样生成的json也不包含该字段。
* @JSONField(serialize=false)
* private String name;
*/

/*
* 第二种:在对象对应字段前面加transient,表示该字段不用序列化,即在生成json的时候就不会包含该字段了。
* private transient String name;
*/

/*
* 第三种:使用fastjson的拦截器
* PropertyFilter profilter = new PropertyFilter(){

        @Override  
        public boolean apply(Object object, String name, Object value) {  
            if(name.equalsIgnoreCase("last")){  
                //false表示last字段将被排除在外  
                return false;  
            }  
            return true;  
        }  

    };  
    json = JSON.toJSONString(user, profilter);  
    System.out.println(json);   

*/

/*
* 第四种,直接填写属性
* SimplePropertyPreFilter filter = new SimplePropertyPreFilter(TTown.class, “id”,”townname”);
response.getWriter().write(JSONObject.toJSONString(townList,filter));

*/

猜你喜欢

转载自blog.csdn.net/qq_35123802/article/details/77369160