Json-lib转对象时过滤不需要的属性

JsonConfig config = new JsonConfig();  
		config.setIgnoreDefaultExcludes(false);     
		config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);   
		config.setExcludes(new String[]{//只要设置这个数组,指定过滤哪些字段。  
//		  "l2Interfaces",  
//		  "OSInstalled",  
		  "ipInterfaces",  
		  "OSRunning",  
		  "fileSystems",  
		  "balanceMan",  
		  "endStation"  
		});  


JSONArray jsonArray = JSONArray.fromObject(str);
		for (int i = 0; i < jsonArray.size(); i++) {
			Object o = jsonArray.get(i);
			//如果不需要过滤,方法可用fromObject(o)
			JSONObject jsonObject = JSONObject.fromObject(o,config);
			tt = (TT)JSONObject.toBean(jsonObject, TT.class);
			System.out.println(tt);
		}


你可能感兴趣的:(object,String,filesystems)