JSON设置过滤属性

json-lib-2.3-jdk15.jar
commons-beanutils-1.7.0.jar
commons-httpclient-3.1.jar
commons-lang-2.3.jar
commons-logging-1.0.4.jar
commons-collections-3.1.jar
ezmorph-1.0.3.jar
这些包可以从一下地方下载:
http://commons.apache.org/index.html
http://json-lib.sourceforge.net/
http://ezmorph.sourceforge.net/
http://www.docjar.com/
如果不关联这些包,则会出现以下错误:
java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher
java.lang.NoClassDefFoundError: org/apache/commons/collections/map/ListOrderedMap
java.lang.NoClassDefFoundError: org/apache/commons/beanutils/DynaBean
java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory


  PageableResult pageableResult =  getBaseService().query(SysUser.class, conditionList);
  Map jsonMap = new HashMap();
  jsonMap.put("rows", pageableResult.getCurrentPage());
  jsonMap.put("total", pageableResult.getMaxRowCount());

//开始设置过滤属性
  JsonConfig jsonConfig = new JsonConfig();  //建立配置文件
  jsonConfig.setIgnoreDefaultExcludes(false);      
  jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);    
  jsonConfig.setExcludes(new String[]{"roles"});  //jsconfig  设置过滤属性  此处过滤SysUser中的roles   SysUser中有 private Set roles = new HashSet(0);

//设置过滤属性结束
  try {

  JSONObject jsonresult = new JSONObject();
   jsonresult =JSONObject.fromObject(jsonMap,jsonConfig);
  } catch (Exception e) {
   e.printStackTrace();
  }

你可能感兴趣的:(JSON)