Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-2260

IDL Json Parsing is lossy, and it could be made more accurate.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • java
    • 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; }
      }
      
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            zolyfarkas Zoltan Farkas
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: