6
Map<String, String> testMap = new HashMap<>();
testMap.put("a", "1");
testMap.put("b", "2");
testMap.put("symbol", "3");
System.out.println(JSON.toJSONString(testMap, SerializerFeature.SortField));
输出结果:
{"a":"1","symbol":"3","b":"2"}
很明显json串中如果包含symbol这个字符,排序就懵了。会发生意想不到的排序结果,可以实验下: asymbol asymbola Symbol等都不能正确排序
在延伸:
Map<String, String> testMap = new HashMap<>(); testMap.put("a", "1"); testMap.put("cmjjjjl", "2"); testMap.put("ca", "3");
System.out.println(JSON.toJSONString(testMap, SerializerFeature.SortField));
这要是有问题的。 fastjson的 SerializerFeature.SortField还是避免使用把它是有问题的!