content: package com.alibaba.fastjson2.example.spring6test.config;
  
  import com.alibaba.fastjson2.JSONReader;
  import com.alibaba.fastjson2.JSONWriter;
  import com.alibaba.fastjson2.support.config.FastJsonConfig;
  import com.alibaba.fastjson2.support.spring6.http.converter.FastJsonHttpMessageConverter;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.http.MediaType;
  import org.springframework.http.converter.HttpMessageConverter;
  import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  
  import java.nio.charset.StandardCharsets;
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * @author jiangqiang
   */
  @Configuration
  @EnableWebMvc
  public class WebMvcConfigurer
          implements org.springframework.web.servlet.config.annotation.WebMvcConfigurer {
      /**
       * 与org.springframework.web.servlet.config.annotation.WebMvcConfigurer.configureMessageConverters()方法的区别是：
       *  使用configureMessageConverters方法会导致springboot不会注入默认的消息转换器
       *
       * @param converters
       */
      @Override
      public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
          FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
          FastJsonConfig config = new FastJsonConfig();
          config.setDateFormat("yyyy-MM-dd HH:mm:ss");
          config.setReaderFeatures(JSONReader.Feature.FieldBased, JSONReader.Feature.SupportArrayToBean);
          config.setWriterFeatures(JSONWriter.Feature.WriteMapNullValue, JSONWriter.Feature.PrettyFormat);
          converter.setFastJsonConfig(config);
          converter.setDefaultCharset(StandardCharsets.UTF_8);
          List<MediaType> supportedMediaTypes = new ArrayList<>();
          supportedMediaTypes.add(MediaType.APPLICATION_JSON);
          supportedMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
          converter.setSupportedMediaTypes(supportedMediaTypes);
          converters.add(0, converter);
      }
  }
  