Untyped read collapses a number literal that does not fit a double

Đang mở
#4,170 3 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@mohitjoshi-hey đang làm issue này rồi.

Từ ngày 13/10/2026.

  • #4178 của @mohitjoshi-hey — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
backend

Hướng nghiên cứu

Start by tracing Java's ForyJson.fromJson handling for Object.class and compare it with the BigDecimal.class path; the issue does not name source files or tests. Reproduce with the decimal literal in the report and check how untyped reads represent fractional numbers. Done means untyped reads preserve all digits and avoid converting values such as 1e400 to infinity.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug
Search before asking
  • I had searched in the issues and found no similar issues.
Version

1.7.7

Component(s)

Java

Minimal reproduce step

fromJson(doc, Object.class) is useful to an application that has to resolve a type after it reads the document, which is what a schemaless cache does. The read keeps a large integer, but it converts any other number to a double first, so a literal with more digits than a double holds is reduced before the application sees it.

import org.apache.fory.json.ForyJson;
import java.math.BigDecimal;

public class NumberLiteralLost {

    public static void main(String[] args) {
        ForyJson json = ForyJson.builder().withFieldMode(true).build();
        String literal = "1.234567890123456789012345678901234567890";
        byte[] doc = literal.getBytes();

        Object untyped = json.fromJson(doc, Object.class);
        System.out.println("read as Object     : " + untyped + "   (" + untyped.getClass().getName() + ")");
        System.out.println("read as BigDecimal : " + json.fromJson(doc, BigDecimal.class));
        System.out.println("the literal        : " + literal);
    }
}
What did you expect to see?

The digits kept, so that the application can build the type it later resolves. Reading the same bytes with BigDecimal.class is exact, as the second line shows, so the parser holds the whole literal at some point.

What did you see instead?

A Double with 17 significant digits. The remaining digits are gone before the application is given the value. 1e400 becomes Infinity in the same way, and 0.1000000000000000055511151231257827021181583404541015625 becomes 0.1.

A large integer is kept: 123456789012345678901234567890 is read as a BigInteger. Only a non-integer literal is reduced.

Anything Else?

No response

Are you willing to submit a PR?
  • I'm willing to submit a PR!
Ngôn ngữ chính
Java
Star
4.6k
Fork
470
Merge trung bình
9 giờ 28 phút
Pull request đã merge (30 ngày)
33

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/fory

Tất cả issue của apache/fory

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.