fastjson过滤字段属性

//第一种方法:

PropertyFilter filter = new PropertyFilter() {
			//过滤不需要的字段
			public boolean apply(Object source, String name, Object value) {
				if("code".equals(name)||"shengid".equals(name)){
					return false;
				}
				return true;
			}
		};
		SerializeWriter sw = new SerializeWriter();
		JSONSerializer serializer = new JSONSerializer(sw);
		serializer.getPropertyFilters().add(filter);
		serializer.write(cityList);
		response.getWriter().write(sw.toString());
//第二种方法:
直接在里面写上需要的字段属性.

	SimplePropertyPreFilter filter = new SimplePropertyPreFilter(TTown.class, "id","townname");
		response.getWriter().write(JSONObject.toJSONString(townList,filter)); 

你可能感兴趣的:(java,json)