How to get large number from JSON response using Groovy

135 Views Asked by At

In ReadyAPI I have a JSON response like:

{
    "Example" : [
       {
         "Name" : "Name_1",
         "Id" : 20100202141652076488478
      }]
}

Now, I want to get this Id using Groovy and save it to a property in ReadyAPI. The problem is that this number is too large and is changed to -6748898691334772962

Before using JsonSlurper I see that the value is correct. After JsonSlurper it changes to -6748898691334772962

What are my options to retain 20100202141652076488478?

1

There are 1 best solutions below

2
On

You can use

import grails.converters.JSON

def json = JSON.parse(yourJson)

20100202141652076488478 comes out correctly as java.math.BigInteger