You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fory.apache.org by "mrniko (via GitHub)" <gi...@apache.org> on 2026/10/12 09:51:51 UTC

[I] Untyped read collapses a number literal that does not fit a double [fory]

mrniko opened a new issue, #4170:
URL: https://github.com/apache/fory/issues/4170

   ### Search before asking
   
   - [x] I had searched in the [issues](https://github.com/apache/fory/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.
   
   ```java
   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!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [I] Untyped read collapses a number literal that does not fit a double [fory]

Posted by "mohitjoshi-hey (via GitHub)" <gi...@apache.org>.
mohitjoshi-hey commented on issue #4170:
URL: https://github.com/apache/fory/issues/4170#issuecomment-6169960030

   Hey, @chaokunyang! Please review this PR and let me know if any change is needed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [I] Untyped read collapses a number literal that does not fit a double [fory]

Posted by "mohitjoshi-hey (via GitHub)" <gi...@apache.org>.
mohitjoshi-hey commented on issue #4170:
URL: https://github.com/apache/fory/issues/4170#issuecomment-6135353996

   Hey, @mrniko! I would like to submit a PR for this issue.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [I] Untyped read collapses a number literal that does not fit a double [fory]

Posted by "mrniko (via GitHub)" <gi...@apache.org>.
mrniko commented on issue #4170:
URL: https://github.com/apache/fory/issues/4170#issuecomment-6138984451

   @mohitjoshi-hey 
   
   Hi! I think it's better to ask @chaokunyang


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [I] Untyped read collapses a number literal that does not fit a double [fory]

Posted by "mohitjoshi-hey (via GitHub)" <gi...@apache.org>.
mohitjoshi-hey commented on issue #4170:
URL: https://github.com/apache/fory/issues/4170#issuecomment-6141553882

   Thanks, @chaokunyang! I will shortly make a PR for this issue.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org