FastJsonHttpMessageConverter 返回json字符串有转义符

@Configuration
public class WebConfigurer extends WebMvcConfigurerAdapter {

  @Override
  public void addInterceptors(InterceptorRegistry interceptorRegistry) {
    interceptorRegistry.addInterceptor(new SignInterceptor()).addPathPatterns("/v1/**");
  }

  public HttpMessageConverter stringConverter() {
    StringHttpMessageConverter converter = new StringHttpMessageConverter(
        Charset.forName("UTF-8"));
    return converter;
  }

  public HttpMessageConverter fastConverter() {
    //1、定义一个convert转换消息的对象
    FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
    //2、添加fastjson的配置信息
    FastJsonConfig fastJsonConfig = new FastJsonConfig();
    fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
    fastJsonConfig.setCharset(Charset.forName("UTF-8"));
    //2-1 处理中文乱码问题
    List fastMediaTypes = new ArrayList<>();
    fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
    fastConverter.setSupportedMediaTypes(fastMediaTypes);
    //3、在convert中添加配置信息
    fastConverter.setFastJsonConfig(fastJsonConfig);
    return fastConverter;
  }

  @Override
  public void extendMessageConverters(List> converters) {
    converters.clear();
    converters.add(stringConverter());
    converters.add(fastConverter());
  }

}

问题原因是FastJsonHttpMessageConverter  前面必须有一个StringHttpMessageConverter,converters里可以查看具体的顺序

你可能感兴趣的:(bug)