-
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
[BUG] BigDecimal 0e-7序列化时候会有bug #2076
Comments
wenshao
added a commit
that referenced
this issue
Dec 6, 2023
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.44-SNAPSHOT/ |
2.0.6版本的实现性能较差,当前的实现不够精确,可以继续改进。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题描述
简要描述您碰到的问题。
调用 JSONObject.toJSONString(jsonObject); 当对象中有bigdecimal = 0e-7 字段时候,IOUtil 在 writeDecimal时候如果off = buffer.size 不会进行扩容,会报数组下标越界
java.lang.ArrayIndexOutOfBoundsException: Index 314928 out of bounds for length 8192
at com.alibaba.fastjson2.util.IOUtils.writeInt64(IOUtils.java:1085)
at com.alibaba.fastjson2.util.IOUtils.writeDecimal(IOUtils.java:381)
at com.alibaba.fastjson2.JSONWriterUTF16.writeDecimal(JSONWriterUTF16.java:1305)
at com.alibaba.fastjson2.writer.ObjectWriterImplMap.write(ObjectWriterImplMap.java:497)
at com.alibaba.fastjson2.writer.ObjectWriterImplMap.write(ObjectWriterImplMap.java:548)
at com.alibaba.fastjson2.JSON.toJSONString(JSON.java:2815)
at com.alibaba.fastjson2.JSONObject.toJSONString(JSONObject.java:1144)
环境信息
请填写以下信息:
重现步骤
如何操作可以重现该问题:
public static void main(String[] args) throws IOException {
String str = String.valueOf(FileUtil.readChars(new File("C:\***\SO1231205000018.txt")));
JSONObject.toJSONString(str);
JSONObject jsonObject = JSONObject.parseObject(str);
JSONObject.toJSONString(jsonObject);
}
等于的时候没有扩容 导致后续数组下标越界
期待的正确结果
对您期望发生的结果进行清晰简洁的描述。
相关日志输出
请复制并粘贴任何相关的日志输出。
java.lang.ArrayIndexOutOfBoundsException: Index 314928 out of bounds for length 8192
at com.alibaba.fastjson2.util.IOUtils.writeInt64(IOUtils.java:1085)
at com.alibaba.fastjson2.util.IOUtils.writeDecimal(IOUtils.java:381)
at com.alibaba.fastjson2.JSONWriterUTF16.writeDecimal(JSONWriterUTF16.java:1305)
at com.alibaba.fastjson2.writer.ObjectWriterImplMap.write(ObjectWriterImplMap.java:497)
at com.alibaba.fastjson2.writer.ObjectWriterImplMap.write(ObjectWriterImplMap.java:548)
at com.alibaba.fastjson2.JSON.toJSONString(JSON.java:2815)
at com.alibaba.fastjson2.JSONObject.toJSONString(JSONObject.java:1144)
附加信息
如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。
json文件在附件
SO1231205000018.txt
:
The text was updated successfully, but these errors were encountered: