Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8478

JsonSlurper in 2.4 loses precision of big integers truncating them to longs

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.4.13
    • Fix Version/s: None
    • Component/s: JSON
    • Labels:
      None

      Description

      Consider the following json string:

       

      {"x":11819408672106971000}

       

      When parsed by a JsonSlurper x value is trimmed to a -6627335401602580616 as a result of the Long overflow.

      The reason for this is the following code in the CharScanner.java starting from line 660:

       

      final int length = index - from;

      if (!foundDot && simple) {
        if (isInteger(buffer, from, length)) {
          value = parseIntFromTo(buffer, from, index);
        } else {
          value = parseLongFromTo(buffer, from, index);
           }
      } else {
        value = parseBigDecimal(buffer, from, length);
      }

      Basically all the numbers besides ones in the scientific notation or containing dots are treated as long at best.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              leftie Alexander Astakhov
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: