解决fastjson自动过滤null值
使用 SerializerFeature.WriteNullStringAsEmpty 解决
List<HistoryVector> historyVectors= new ArrayList<>();
HistoryVector historyVector = new HistoryVector();
historyVector.setInput("1");
historyVector.setReason("111111");
historyVector.setResult(null);
historyVectors.add(historyVector);
System.out.println(JSON.toJSONString(historyVector));
System.out.println(JSON.toJSONString(historyVector, SerializerFeature.WriteNullStringAsEmpty));
输出的信息
{"input":"1","reason":"111111"}
{"case_desc":"","input":"1","reason":"111111","result":""}
当然你也可以写成一个配置,无需在每个JSON.toJSONString里面添加参数,以下为fastjson SerializerFeature其他方法