1. 序列化时格式化日期
String s = JSON.toJSONStringWithDateFormat(map, "yyyy-MM-dd'T'HH:mm:ss");
2. 反序列化Map时小数和日期处理
Feature.AllowISO8601DateFormat对应的日期格式为: “yyyy-MM-dd’T’HH:mm:ss”
int disableDecimalFeature = JSON.DEFAULT_PARSER_FEATURE & ~Feature.UseBigDecimal.getMask();
HashMap data = JSON.parseObject(JSON.toJSONString(map.getJSONObject("data")), HashMap.class,disableDecimalFeature, Feature.AllowISO8601DateFormat);
全局改:
JSON.DEFAULT_PARSER_FEATURE &= ~Feature.UseBigDecimal.getMask();
3. 反序列化内部嵌套类未序列化解决
Type type = new TypeReference<Map<String, List<MachineData>>>() {}.getType();
Map<String, List<MachineData>> listMap = JSON.parseObject(str, type);
其他Feature:
参考:https://www.codenong.com/js1454d45c76e0/