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<String, Object> jsonMap = new HashMap<String, Object>();
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<Role> roles = new HashSet<Role>(0);
//設定過濾屬性結束
try {
JSONObject jsonresult = new JSONObject();
jsonresult =JSONObject.fromObject(jsonMap,jsonConfig);
} catch (Exception e) {
e.printStackTrace();
}