Fastjson的SerializerFeature序列化属性
QuoteFieldNames———-输出key时是否使用双引号,默认为true
WriteMapNullValue——–是否输出值为null的字段,默认为false
WriteNullNumberAsZero—-数值字段如果为null,输出为0,而非null
WriteNullListAsEmpty—–List字段如果为null,输出为[],而非null
WriteNullStringAsEmpty—字符类型字段如果为null,输出为”“,而非null
WriteNullBooleanAsFalse–Boolean字段如果为null,输出为false,而非null
package com.springsecuritydemo.util;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//Arbor 2022/9/29
public class WebUtils {
/**
* 渲染String页面
* @param httpServletResponse
* @param responseObject
*/
public static void renderResponse(HttpServletResponse httpServletResponse, ResponseObject responseObject){
httpServletResponse.setStatus(200);
httpServletResponse.setContentType("application/json");
httpServletResponse.setCharacterEncoding("utf-8");
try {
httpServletResponse.getWriter().print(JSONObject.toJSONString(responseObject, SerializerFeature.WriteMapNullValue));
} catch (IOException e) {
e.printStackTrace();
}
}
}
标签:输出,httpServletResponse,SerializerFeature,Json,WriteMapNullValue,import,null
From: https://www.cnblogs.com/Arborblog/p/16742403.html