Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Open
macroguo-ghy opened this issue Dec 18, 2024 · 0 comments
Open
Labels
bug Something isn't working

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant