开发者社区> 问答> 正文

fastjson2里面找不到FastJsonHttpMessageConverter

提问1.png

fast2里面的support没有FastJsonHttpMessageConverter

提问2.png

fast2-extension里面也没有找到FastJsonHttpMessageConverter 原提问者GitHub用户CreasyWorld

展开
收起
白夜行fighting 2023-04-21 10:39:47 653 0
2 条回答
写回答
取消 提交回答
  • fast2集成 https://alibaba.github.io/fastjson2/spring_support_cn

    回答1.png

    回答2.png

    原回答者GitHub用户CreasyWorld

    2023-04-21 12:35:30
    赞同 展开评论 打赏
  • 随心分享,欢迎友善交流讨论:)

    在Fastjson 2.x中,FastJsonHttpMessageConverter被移除了,它的功能被集成到了Spring的MappingJackson2HttpMessageConverter中。因此,如果你想在Spring MVC应用程序中使用Fastjson 2.x作为JSON消息转换器,你需要使用以下代码来注册FastjsonHttpMessageConverter:

    @Configuration public class WebConfig extends WebMvcConfigurerAdapter {

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        // Remove the default converters
        converters.clear();
    
        // Add the Fastjson converter
        FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
        converters.add(converter);
    }
    

    } 在上面的代码中,我们首先清空了默认的转换器,然后创建了一个FastJsonHttpMessageConverter对象并将其添加到转换器列表中。这将使Spring在处理HTTP请求和响应时使用Fastjson作为JSON消息转换器。

    需要注意的是,在使用Fastjson 2.x时,你需要确保所有使用JSON数据的地方都是安全的,以避免发生JSON注入等安全问题。

    2023-04-21 11:04:47
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载