阿里fastjson与fastjson2输出对象null值字段

解决fastjson将序列化null值字段丢失

fastjson1:

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;

// 设置 SerializerFeature 中的 WriteMapNullValue 参数
String jsonString = JSON.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue)

fastjson2:

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONWriter;

String jsonString = JSON.toJSONString(jsonObject, JSONWriter.Feature.WriteMapNullValue, JSONWriter.Feature.WriteNullListAsEmpty);

你可能感兴趣的:(Java,json,java)