json格式字符串中的日期是按照‘yyyy-MM-dd HH:mm:ss’格式,如果按照常规的转换为对象,该日期则解析成当前系统时间
- JSONObject json = JSONObject.fromObject(data);
- Dispatchplan dp = (Dispatchplan)JSONObject.toBean(json,Dispatchplan.class);
导致原因JSONObject可能无法识别日期格式,做了以下修改就解决\
- Dispatchplan dp = new Dispatchplan();
- JSONObject json = JSONObject.fromObject(data);
- String[] dateFormats = new String[] {"yyyy-MM-dd HH:mm:ss"};
- JSONUtils.getMorpherRegistry().registerMorpher(new DateMorpher(dateFormats));
- dp = (Dispatchplan)JSONObject.toBean(json,Dispatchplan.class);