jsonconfig处理bean中的日期类型

Map bean = new HashMap();
		bean.put("d", new Date());
		List l = new ArrayList();
		l.add("a");
		l.add("b");
		bean.put("l", l);
		JsonConfig jsonConfig = new JsonConfig(); 
		final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
		jsonConfig.registerJsonValueProcessor(Date.class, new JsonValueProcessor() {
			public Object processArrayValue(Object value, JsonConfig jsonConfig) {
				return value;
			}
			public Object processObjectValue(String key, Object value, JsonConfig jsonConfig) {
				if(value instanceof Date){
					return sdf.format((Date)value);
				}
				return value;
			}
		});
		System.out.println(JSONObject.fromObject(bean, jsonConfig));

 

你可能感兴趣的:(config)