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());
jsonlib里toJson将日期格式化掉:Java-Json
JsonConfig config = new JsonConfig(); config.registerJsonValueProcessor(Date.class, new JsonValueProcessor() { private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @Override public Object processObjectValue(String key, Object value, JsonConfig cfg) { return format.format((Date)value); } @Override public Object processArrayValue(Object value, JsonConfig cfg) { return format.format((Date)value); } });
fromObject的时候携带上这个config即可