Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
None
-
None
-
None
Description
Currently all integers are handled as Long, and all floating point as Double, having basically the following issues:
1) cannot handle numbers larger that MAXLONG.
2) introducing unnecessary precision
JsonNode Json() : { String s; Token t; JsonNode n; } { ( s = JsonString() { n = new TextNode(s); } | (t=<INTEGER_LITERAL> { n = new LongNode(Long.parseLong(t.image)); }) | (t=<FLOATING_POINT_LITERAL> {n=new DoubleNode(Double.parseDouble(t.image));}) | n=JsonObject() | n=JsonArray() | ( "true" { n = BooleanNode.TRUE; } ) | ( "false" { n = BooleanNode.FALSE; } ) | ( "null" { n = NullNode.instance; } ) ) { return n; } }
This should be improved to:
JsonNode Json() : { String s; Token t; JsonNode n; } { ( s = JsonString() { n = new TextNode(s); } | (t=<INTEGER_LITERAL> { try { n = new IntNode(Integer.parseInt(t.image)); } catch(NumberFormatException e) { try { n = new LongNode(Long.parseLong(t.image)); } catch(NumberFormatException ex2) { n = new BigIntegerNode(new java.math.BigInteger(t.image)); } } }) | (t=<FLOATING_POINT_LITERAL> {n=new DecimalNode(new java.math.BigDecimal(t.image));}) | n=JsonObject() | n=JsonArray() | ( "true" { n = BooleanNode.TRUE; } ) | ( "false" { n = BooleanNode.FALSE; } ) | ( "null" { n = NullNode.instance; } ) ) { return n; } }