Zoltan Farkas created AVRO-2260:
-----------------------------------
Summary: IDL Json Parsing is lossy, and it could be made more
accurate.
Key: AVRO-2260
URL: https://issues.apache.org/jira/browse/AVRO-2260
Project: Apache Avro
Issue Type: Bug
Reporter: Zoltan Farkas
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
{code}
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; }
}
{code}
This should be improved to:
{code}
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; }
}
{code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)