分类

链接

2024 年 3 月
 123
45678910
11121314151617
18192021222324
25262728293031

近期文章

热门标签

新人福利,免费薅羊毛

现在位置:    首页 > JAVA > 正文
共享办公室出租
接收企微事件回调 Content type ‘text/xml;charset=UTF-8’ not supported
JAVA 暂无评论 阅读(101)
@Log4j2
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {

  @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        super.configureMessageConverters(converters);

        //支持XML
        List<MediaType> xmlMediaTypes = new ArrayList<>();
        xmlMediaTypes.add(MediaType.TEXT_XML);
        StringHttpMessageConverter xmlMessageConverter = new StringHttpMessageConverter();
        xmlMessageConverter.setSupportedMediaTypes(xmlMediaTypes);
        converters.add(xmlMessageConverter);

        //JSON
        FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        fastJsonConfig.setSerializerFeatures(
                SerializerFeature.PrettyFormat,
                //int类型的key 加引号
                SerializerFeature.WriteNonStringKeyAsString,
                //保留map空的字段
                SerializerFeature.WriteMapNullValue,
                //将Number类型的null转成0
                SerializerFeature.WriteNullNumberAsZero,
                // 将List类型的null转成[]
                SerializerFeature.WriteNullListAsEmpty,
                // 将Boolean类型的null转成false
                SerializerFeature.WriteNullBooleanAsFalse);
        fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
        //处理中文乱码问题
        List<MediaType> fastMediaTypes = new ArrayList<>();
        fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
        fastConverter.setSupportedMediaTypes(fastMediaTypes);
        fastConverter.setFastJsonConfig(fastJsonConfig);
        converters.add(fastConverter);

    }


}

 

============ 欢迎各位老板打赏~ ===========

本文版权归Bruce's Blog所有,转载引用请完整注明以下信息:
本文作者:Bruce
本文地址:接收企微事件回调 Content type ‘text/xml;charset=UTF-8’ not supported | Bruce's Blog

发表评论

留言无头像?