jsonlib对date类型的双向转换
jsonlib里toBean对格式化的日期进行转换:JSON-Java
JSONObject json = JSONObject.fromObject(str);JSONUtils.getMorpherRegistry().registerMorpher(new DateMorpher(new String[]{"yyyy-MM-dd HH:mm:ss"}));App app = (App) json.toBean(json, App.class);System.out.println(app.getCreateTime());
JsonConfig config = new JsonConfig();config.registerJsonValueProcessor(Date.class, new JsonValueProcessor() {private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");@Overridepublic Object processObjectValue(String key, Object value, JsonConfig cfg) {return format.format((Date)value);}@Overridepublic Object processArrayValue(Object value, JsonConfig cfg) {return format.format((Date)value);}});