@ -3,7 +3,6 @@ package com.company.project.configurer;
import java.io.IOException ;
import java.io.IOException ;
import java.nio.charset.Charset ;
import java.nio.charset.Charset ;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Collections ;
import java.util.Collections ;
import java.util.List ;
import java.util.List ;
@ -25,7 +24,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory ;
import org.slf4j.LoggerFactory ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.http.MediaType ;
import org.springframework.http.converter.HttpMessageConverter ;
import org.springframework.http.converter.HttpMessageConverter ;
import org.springframework.web.method.HandlerMethod ;
import org.springframework.web.method.HandlerMethod ;
import org.springframework.web.servlet.HandlerExceptionResolver ;
import org.springframework.web.servlet.HandlerExceptionResolver ;
@ -51,14 +49,11 @@ public class WebMvcConfigurer extends WebMvcConfigurerAdapter {
public void configureMessageConverters ( List < HttpMessageConverter < ? > > converters ) {
public void configureMessageConverters ( List < HttpMessageConverter < ? > > converters ) {
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter ( ) ;
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter ( ) ;
FastJsonConfig config = new FastJsonConfig ( ) ;
FastJsonConfig config = new FastJsonConfig ( ) ;
config . setSerializerFeatures ( SerializerFeature . WriteMapNullValue ) ; //保留空的字段
config . setSerializerFeatures ( SerializerFeature . WriteMapNullValue , //保留空的字段
//SerializerFeature.WriteNullStringAsEmpty,//String null -> ""
SerializerFeature . WriteNullStringAsEmpty , //String null -> ""
//SerializerFeature.WriteNullNumberAsZero//Number null -> 0
SerializerFeature . WriteNullNumberAsZero ) ; //Number null -> 0
// 按需配置,更多参考FastJson文档哈
converter . setFastJsonConfig ( config ) ;
converter . setFastJsonConfig ( config ) ;
converter . setDefaultCharset ( Charset . forName ( "UTF-8" ) ) ;
converter . setDefaultCharset ( Charset . forName ( "UTF-8" ) ) ;
converter . setSupportedMediaTypes ( Arrays . asList ( MediaType . APPLICATION_JSON_UTF8 ) ) ;
converters . add ( converter ) ;
converters . add ( converter ) ;
}
}