Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

DenineLu
Copy link

@DenineLu DenineLu commented Apr 8, 2025

问题描述

当request json如下时
"{[]:{"page": 2, "table1":{}}}"

在AbstractObjectParser中parse(String name, boolean isReuse)方法,获取request key时会出现class com.alibaba.fastjson.JSONArray cannot be cast to class java.lang.String 异常,如图所示
image

原因是对于低版本的fastjson,如1.2.21,允许自动进行JSONArray to String的转换,当前使用的1.2.83版本已禁止该隐式转换。

@DenineLu
Copy link
Author

DenineLu commented Apr 8, 2025

@TommyLemon cc

@TommyLemon TommyLemon merged commit f39d269 into Tencent:master Apr 11, 2025
1 check passed
@TommyLemon
Copy link
Collaborator

TommyLemon commented Apr 12, 2025

感谢小红书工程师的贡献,已合并~
不过 [] 这种特殊字符作为 key 没有引号包裹,不符合 JSON 规范,建议改成 "[]" ,这样其实也不会触发这个 bug。
APIJSON 8 已去除 fastjson,可以使用 jackson, gson, fastjson2 等各种其它 JSON 库了
#810

3 个 Demo 已使用 APIJSON 8
https://github.com/APIJSON/APIJSON-Demo/commits/master/APIJSON-Java-Server
Image

当然这个也导致初始化麻烦一些,需要重写 parseObject, parseArray, toJSONString 等方法,用具体的 JSON 库来反序列化,
打算后续提供 apijson-fastjson2, apijson-jackson, apijson-gson 等对应插件,引入后可以简化这部分代码:
https://github.com/APIJSON/APIJSON-Demo/blob/eb051b0df273f30479b10d1238d666e4ed2efadd/APIJSON-Java-Server/APIJSONDemo/src/main/java/apijson/demo/DemoApplication.java#L81-L127

@TommyLemon
Copy link
Collaborator

TommyLemon commented May 11, 2025

APIJSON 8.0.0 已发布:去 fastjson; 增 Doris
https://github.com/Tencent/APIJSON/releases/tag/8.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants