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] JSONObject Cast Exception #2534

Closed
Cooper-Zhong opened this issue May 7, 2024 · 3 comments
Closed

[BUG] JSONObject Cast Exception #2534

Cooper-Zhong opened this issue May 7, 2024 · 3 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@Cooper-Zhong
Copy link
Contributor

问题描述

类似 #2520,出现JSONObject Cast Exception

环境信息

  • OS信息: [MacOS 12.7.4 M1 Pro 16 GB]
  • JDK信息: [Openjdk 17.0.6]
  • 版本信息:[Fastjson 2.0.49]

重现步骤

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue1070Mutated_21 {

    @Test
    public void testExtract1Mutatedfj() {
        String raw = "[[{\"a\":1},{\"a\":2}],[{\"a\":3}]]";
        assertEquals("{\"a\":2}", ((JSONObject) JSONPath.extract(raw, "$[0][1]")).toJSONString());
    }   
}

期待的正确结果

正常转换

相关日志输出

java.lang.ClassCastException: class com.alibaba.fastjson2.JSONObject cannot be cast to class com.alibaba.fastjson.JSONObject (com.alibaba.fastjson2.JSONObject and com.alibaba.fastjson.JSONObject are in unnamed module of loader 'app')

@Cooper-Zhong Cooper-Zhong added the bug Something isn't working label May 7, 2024
wenshao added a commit that referenced this issue May 7, 2024
@wenshao wenshao added this to the 2.0.50 milestone May 7, 2024
@wenshao
Copy link
Member

wenshao commented May 7, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.50-SNAPSHOT/
这个问题我没重现,但我还是做了修复处理,请帮忙用2.0.50-SNAPSHOT版本在你本地验证下

@wenshao wenshao added the fixed label May 7, 2024
@Cooper-Zhong
Copy link
Contributor Author

Together with #2520 经验证无问题。辛苦温少

@wenshao
Copy link
Member

wenshao commented May 12, 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 fixed
Projects
None yet
Development

No branches or pull requests

2 participants