SpringMVC | 返回值序列化配置

@Configuration
public class AppWevbConfig {

    /**
     * 自定义消息转化器
     *
     * @return
     */
    @Bean
    public HttpMessageConverters getFastJsonHttpMessageConverter() {
        FastJsonHttpMessageConverter fjc = new FastJsonHttpMessageConverter();
        FastJsonConfig fj = new FastJsonConfig();
        //QuoteFieldNames———-输出key时是否使用双引号,默认为true
        //WriteMapNullValue——–是否输出值为null的字段,默认为false
        //WriteNullNumberAsZero—-数值字段如果为null,输出为0,而非null
        //WriteNullListAsEmpty—–List字段如果为null,输出为[],而非null
        //WriteNullStringAsEmpty—字符类型字段如果为null,输出为”“,而非null
        //WriteNullBooleanAsFalse–Boolean字段如果为null,输出为false,而非null
        //DisableCircularReferenceDetect :消除对同一对象循环引用的问题,默认为false(如果不配置有可能会进入死循环)
        fj.setSerializerFeatures(
                SerializerFeature.QuoteFieldNames,
                SerializerFeature.WriteNullListAsEmpty,
                SerializerFeature.WriteNullBooleanAsFalse,
                SerializerFeature.BrowserCompatible,
                SerializerFeature.WriteSlashAsSpecial,
                SerializerFeature.WriteDateUseDateFormat,
                SerializerFeature.DisableCircularReferenceDetect
        );
        fjc.setFastJsonConfig(fj);
        return new HttpMessageConverters(fjc);
    }
}

你可能感兴趣的:(Spring,SpringBoot,开发语言,spring,mvc)