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] JSONArray Cast Exception #2520

Closed
Cooper-Zhong opened this issue May 6, 2024 · 2 comments
Closed

[BUG] JSONArray Cast Exception #2520

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

Comments

@Cooper-Zhong
Copy link
Contributor

问题描述

ClassCastException: class com.alibaba.fastjson2.JSONArray cannot be cast to class com.alibaba.fastjson.JSONArray

环境信息

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

重现步骤

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

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

public class Issue113_Mutated_137 {

    @Test
    public void test() {
        String testJson2 = "{\"result\":[{\"puid\":\"21025318\"},{\"puid\":\"21482682\"},{\"puid\":\"21025345\"}],\"state\":0}";
        JSONArray result2 = (JSONArray) JSONPath.extract(testJson2, "$.result[0,2].puid");
        assertNotNull(result2);
        assertEquals("[\"21025318\",\"21025345\"]", result2.toJSONString());
    }
}

期待的正确结果

在Fastjson2-2.0.49中 测试正常

相关日志输出

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

@Cooper-Zhong Cooper-Zhong added the bug Something isn't working label May 6, 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/fastjson/2.0.50-SNAPSHOT/
问题已修复,请帮忙用2.0.50-SNAPSHOT版本验证,2.0.50版本预计在5月12日前发布

@wenshao
Copy link
Member

wenshao commented May 12, 2024

https://github.com/alibaba/fastjson2/releases/tag/2.0.50
2.0.50已发布,请用新版本

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