Skip to content

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

Closed
@macroguo-ghy

Description

问题描述

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)

期待的正确结果

两者表现相同

相关日志输出

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

附加信息

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

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions