-
Notifications
You must be signed in to change notification settings - Fork 510
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
[QUESTION]2.0.47存在反序列化数值溢出问题 #2305
Comments
它确实就溢出了, 不想溢出可以使用 BigInteger 或者 BigDecimal 类型 |
这个-1000值虽不合理,但在2.0.47之前都能正常运行,到了2.0.47之后就会出现程序异常了.只想要能够和之前的保持一致. |
缺省抛异常是合理的,但应该加一个JSONReader.Feature给用户选择是否抛异常 |
如果选择忽略这个异常,给什么值合适呢?包装类给 null 值,基本类型给 0? |
BigInteger bigInt = new BigInteger("18446744073709550616");
String s = "{\"value\": " + bigInt + "}";
@Test
public void test() {
assertThrows(
JSONException.class,
() -> JSON.parseObject(s, Bean.class));
Bean bean = JSON.parseObject(s, Bean.class, JSONReader.Feature.NonErrorOnNumberOverflow);
assertEquals(bean.value, bigInt.longValue());
}
public static class Bean {
public long value;
} https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.48-SNAPSHOT/ |
测试过 2.0.5 , 2.0.46都能正常反序列化,但是2.0.47就存在溢出报错
2.0.47之前版本显示
2.0.47版本显示
The text was updated successfully, but these errors were encountered: