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] jsonArrary.getBigDecimal with boolean value #2745

Closed
Cooper-Zhong opened this issue Jun 27, 2024 · 1 comment
Closed

[BUG] jsonArrary.getBigDecimal with boolean value #2745

Cooper-Zhong opened this issue Jun 27, 2024 · 1 comment
Labels
bug Something isn't working fixed
Milestone

Comments

@Cooper-Zhong
Copy link
Contributor

问题描述

fastjson 兼容使用getBigDecimal时报错,fastjson2无问题。

jsonArray.add(true);
jsonArray.getBigDecimal(0); // exception

环境信息

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

重现步骤

import com.alibaba.fastjson2.JSONArray;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.math.BigInteger;

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

public class fastjson_Issue673Mutated_310 {
    @Test
    public void mutatedTest() throws Exception {
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(true);
        assertEquals(BigDecimal.ONE, jsonArray.getBigDecimal(0));
    }
    @Test
    public void mutatedTest_fj() throws Exception {
        com.alibaba.fastjson.JSONArray jsonArray = new com.alibaba.fastjson.JSONArray();
        jsonArray.add(true);
        assertEquals(BigDecimal.ONE, jsonArray.getBigDecimal(0));
    }
}

相关日志输出

com.alibaba.fastjson.JSONException: Can not cast 'class java.lang.Boolean' to BigDecimal
at com.alibaba.fastjson.JSONArray.getBigDecimal(JSONArray.java:213)

@Cooper-Zhong Cooper-Zhong added the bug Something isn't working label Jun 27, 2024
@wenshao wenshao added this to the 2.0.52 milestone Jun 29, 2024
@wenshao wenshao added the fixed label Jun 29, 2024
@wenshao
Copy link
Member

wenshao commented Jul 14, 2024

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

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