-
Notifications
You must be signed in to change notification settings - Fork 495
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
默认配置会使用BigInteger来parse大数值,无法设置为Long #2612
Labels
Milestone
Comments
为什么有这个需求啊? |
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.51-SNAPSHOT/ public abstract class JSONReader {
public enum Feature {
/**
* Feature that determines whether JSON integral (non-floating-point)
* numbers are to be deserialized into {@link java.math.BigInteger}s
* if only generic type description (either {@link Object} or
* {@link Number}, or within untyped {@link java.util.Map}
* or {@link java.util.Collection} context) is available.
* If enabled such values will be deserialized as
* {@link java.math.BigInteger}s;
* if disabled, will be deserialized as "smallest" available type,
* which is either {@link Integer}, {@link Long} or
* {@link java.math.BigInteger}, depending on number of digits.
* <p>
* Feature is disabled by default, meaning that "untyped" integral
* numbers will by default be deserialized using whatever
* is the most compact integral type, to optimize efficiency.
* @since 2.0.51
*/
UseBigIntegerForInts(1 << 29),
/**
* Feature that determines how "small" JSON integral (non-floating-point)
* numbers -- ones that fit in 32-bit signed integer (`int`) -- are bound
* when target type is loosely typed as {@link Object} or {@link Number}
* (or within untyped {@link java.util.Map} or {@link java.util.Collection} context).
* If enabled, such values will be deserialized as {@link java.lang.Long};
* if disabled, they will be deserialized as "smallest" available type,
* {@link Integer}.
*<p>
* Note: if {@link #UseBigIntegerForInts} is enabled, it has precedence
* over this setting, forcing use of {@link java.math.BigInteger} for all
* integral values.
*<p>
* Feature is disabled by default, meaning that "untyped" integral
* numbers will by default be deserialized using {@link java.lang.Integer}
* if value fits.
*
* @since 2.0.51
*/
UseLongForInts(1 << 30);
}
}
|
最近在做fastjson1到2升级时,默认行为被更改了,导致很多地方需要手动修改,希望可以通过参数全局配置,感谢大佬! |
https://github.com/alibaba/fastjson2/releases/tag/2.0.51 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题:
测试fastjson1默认反序列化大数值为long:
fastjson2默认反序列化大数值为BigInteger,且无法修改:
只能通过自定义setter方法进行设置:
小数有类似的配置,但是整数没有找到:
希望添加类似配置,可以选择反序列化大数值的默认行为。
The text was updated successfully, but these errors were encountered: