解決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其他方法