|  |  | 
 |  |  | import org.springframework.context.annotation.Configuration; | 
 |  |  | import org.springframework.http.MediaType; | 
 |  |  | import org.springframework.http.converter.HttpMessageConverter; | 
 |  |  | //import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | 
 |  |  | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | 
 |  |  |  | 
 |  |  | import java.nio.charset.StandardCharsets; | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.List; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 必须实现WebMvcConfigurer否则不启作用,即Controller转json时不用fastjson | 
 |  |  |  */ | 
 |  |  | @Configuration | 
 |  |  | public class FastJsonConfig  { | 
 |  |  | public class FastJsonConfig implements WebMvcConfigurer { | 
 |  |  |     /** | 
 |  |  |      * 配置fastjson输出格式 | 
 |  |  |      **/ | 
 |  |  |     @SuppressWarnings("unused") | 
 |  |  |     @Override | 
 |  |  |     public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { | 
 |  |  |         // 1. 配置fastjson | 
 |  |  |         com.alibaba.fastjson2.support.config.FastJsonConfig config = new com.alibaba.fastjson2.support.config.FastJsonConfig(); | 
 |  |  | 
 |  |  |                 JSONWriter.Feature.WriteMapNullValue, | 
 |  |  |                 //输出null的boolean 为 false | 
 |  |  |                 JSONWriter.Feature.WriteNullBooleanAsFalse, | 
 |  |  |                 //把Long型输出为String | 
 |  |  |                 //把Long型输出为String,在pojo的属性中个性设置 | 
 |  |  |                 //JSONWriter.Feature.WriteLongAsString, | 
 |  |  |                 //输出null的list 为 [] | 
 |  |  |                 JSONWriter.Feature.WriteNullListAsEmpty, | 
 |  |  |                 //输出null的number 为 0 | 
 |  |  |                 JSONWriter.Feature.WriteNullNumberAsZero, | 
 |  |  |                 //JSONWriter.Feature.WriteNullNumberAsZero, | 
 |  |  |                 //输出null字符串 为 "" | 
 |  |  |                 JSONWriter.Feature.WriteNullStringAsEmpty, | 
 |  |  |                 //对map进行排序 |