开发者社区> 问答> 正文

1.1.6版本中升级了fastjson2之后,CanalRabbitMQConsumer中使用JSO

// json中带null的会报错, 比如这个ALTER语句产生的消息 String messageData = "{"data":null,"database":"canal-test-to1","es":1654937242000,"id":153,"isDdl":true,"mysqlType":null,"old":null,"pkNames":null,"sql":"ALTER TABLE canal-test-to1.test_table1 ADD COLUMN birthday date NULL","sqlType":null,"table":"test_table1","ts":1654937242664,"type":"ALTER"}"; CommonMessage commonMessage = JSON.parseObject(messageData, CommonMessage.class); System.out.println(commonMessage);

异常栈信息

Exception in thread "main" com.alibaba.fastjson2.JSONException: json format error : n at com.alibaba.fastjson2.reader.FieldReaderListStrMethod.readFieldValue(FieldReaderListStrMethod.java:83) at com.alibaba.fastjson2.reader.ObjectReaderBean.readObject(ObjectReaderBean.java:174) at com.alibaba.fastjson2.JSON.parseObject(JSON.java:258)

// 把null去掉就没问题 String messageData = "{"database":"canal-test-to1","es":1654937242000,"id":153,"isDdl":true,"sql":"ALTER TABLE canal-test-to1.test_table1 ADD COLUMN birthday date NULL","table":"test_table1","ts":1654937242664,"type":"ALTER"}"; CommonMessage commonMessage = JSON.parseObject(messageData, CommonMessage.class); System.out.println(commonMessage);

换成旧版本的fastjson上面的代码都没问题

原提问者GitHub用户jimmy384

展开
收起
白夜行fighting 2023-04-25 21:21:10 279 0
1 条回答
写回答
取消 提交回答
  • fastjson2 已升级到2.0.7,已修复

    原回答者GitHub用户agapple

    2023-04-26 18:03:01
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

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