Spring 返回字符串类型带双引号

问题:用spring定义返回类型为String,预期返回: zhangsan,结果返回:"zhangsan"

原因:  使用公司研发框架,对字符串类型定义做了处理,导致返回字符串加双引号(既jsonString类型字符串),怎么定义实现WebMvcConfigurer 做处理都无法转换,是由于框架里面已经对这个做了实现并制定优先级为0,导致自己写的无效,框架部分代码实现如下

public class FastJsonDesensitizationConfigurationimplements WebMvcConfigurer {

public FastJsonDesensitizationConfiguration() {

}

public void extendMessageConverters(List> converters) {

FastJsonHttpMessageConverter fastJsonConverter =new FastJsonHttpMessageConverter();

        List mediaTypes =new ArrayList();

        mediaTypes.add(MediaType.APPLICATION_JSON);

        mediaTypes.add(MediaType.APPLICATION_JSON_UTF8);

        mediaTypes.add(new MediaType("application", "*+json"));

        fastJsonConverter.setSupportedMediaTypes(mediaTypes);

        FastJsonConfig fastJsonConfig =new FastJsonConfig();

        fastJsonConfig.setSerializerFeatures(new SerializerFeature[]{SerializerFeature.BrowserSecure, SerializerFeature.WriteMapNullValue, SerializerFeature.PrettyFormat, SerializerFeature.DisableCircularReferenceDetect});

        fastJsonConfig.setSerializeFilters(new SerializeFilter[]{FastJsonFilterForDesensitize.getInstance()});

        fastJsonConverter.setFastJsonConfig(fastJsonConfig);

        converters.add(0, fastJsonConverter);

    }

}

解决问题:在请求参数里面加 produces = MediaType.TEXT_PLAIN_VALUE配置,指定返回参数格式,代码截图如下

你可能感兴趣的:(Spring 返回字符串类型带双引号)