Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG]key为map类型的字符串,fastjson2兼容版无法解析 #3214

Closed
macroguo-ghy opened this issue Dec 18, 2024 · 1 comment
Closed
Labels
bug Something isn't working fixed
Milestone

Comments

@macroguo-ghy
Copy link

问题描述

key为map类型的字符串fastjson2兼容版无法解析

环境信息

  • OS信息: macos m2
  • JDK信息:Openjdk 17
  • 版本信息:Fastjson2 2.0.53

重现步骤

{
  "k1":{
    "k2":[
      {
        {} : {}
      }
    ]
  }
}
String json = "{\n"
                + "  \"k1\":{\n"
                + "    \"k2\":[\n"
                + "      {\n"
                + "        {} : {}\n"
                + "      }\n"
                + "    ]\n"
                + "  }\n"
                + "}";
JSONObject jsonObject = JSON.parseObject(json);

fastjson1不报错,fastjson2兼容版本报错

java.lang.ClassCastException: class com.alibaba.fastjson.JSONObject cannot be cast to class java.lang.String (com.alibaba.fastjson.JSONObject is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')
	at com.alibaba.fastjson.JSONObject.put(JSONObject.java:49)
	at com.alibaba.fastjson2.JSONReader.readObject(JSONReader.java:2354)
	at com.alibaba.fastjson2.JSONReader.readArray(JSONReader.java:2579)
	at com.alibaba.fastjson2.JSONReader.readObject(JSONReader.java:2308)
	at com.alibaba.fastjson2.JSONReader.read(JSONReader.java:2108)
	at com.alibaba.fastjson.JSON.parseObject(JSON.java:189)

期待的正确结果

两者表现相同

相关日志输出

请复制并粘贴任何相关的日志输出。

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。

@macroguo-ghy macroguo-ghy added the bug Something isn't working label Dec 18, 2024
@macroguo-ghy macroguo-ghy changed the title [BUG]key为map类型的字符串fastjson2兼容版无法解析 [BUG]key为map类型的字符串,fastjson2兼容版无法解析 Dec 18, 2024
@wenshao wenshao added this to the 2.0.54 milestone Dec 30, 2024
wenshao added a commit that referenced this issue Jan 1, 2025
* compatible api support non-string key, for issue #3214
@wenshao wenshao added the fixed label Jan 1, 2025
@wenshao
Copy link
Member

wenshao commented Jan 12, 2025

https://github.com/alibaba/fastjson2/releases/tag/2.0.54
问题已修复,请用新版本

@wenshao wenshao closed this as completed Jan 12, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants