`public class JsonUtil {java
//该方法的参数,Object为即将转化的java对象,string.... properties表明不转译的字段 public static String toJSONString(Object object,String ... properties) { //建立一个Filter, SimplePropertyPreFilter filter = new SimplePropertyPreFilter(); for(String property : properties) { //向filter中添加不转译的字段 filter.getExcludes().add(property); } //返回使用的为JSON的.toJSONSTRING的方法,参数为java对象,和建立的拦截器对象,后面两个参数为固定格式 return JSON.toJSONString(object,filter,SerializerFeature.PrettyFormat,SerializerFeature.DisableCircularReferenceDetect); }
}`code