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即可