0

I have a file with some data and configuration parameters that i need to change before I use it as body data for POST rest call.

So I am using slurper to get the configuration value

JsonSlurper slurper = new JsonSlurper()
def inputFile = new File("file.json")
def parsedInput = slurper.parse(inputFile)

Then I change the desired configuration parameter

parsedInput.config.id = 1

And then modified input file is written to the temporary file

def tempFile = new File("temp.json")
tempFile.write(JsonOutput.toJson(parsedInput))

I was quite surprised when I realized that the output file is three times larger than the input. I have checked the content and it looks like slurper changed the float precision.

Before modification

0.145,
0.144,
0.145,

After modification

0.1459999999999999908961711980737163685262203216552734375, 
0.1449999999999999900079927783735911361873149871826171875, 
0.1459999999999999908961711980737163685262203216552734375

Any ideas how to fix it?

EDIT 1: added some input data

http://wklej.org/hash/4de6639a5bf/txt/

user2847238
  • 169
  • 3
  • 14
  • Do you have some example input json? – tim_yates Apr 06 '16 at 10:36
  • Added link to the input file – user2847238 Apr 06 '16 at 11:23
  • 1
    @user2847328 Seriously, that's the best example you could come up with? A massive massive file? Four lines pasted here that demonstrated the problem would have been better than Megs of off-site json which will probably no longer be there when someone else has the same issue later on and finds this question... – tim_yates Apr 06 '16 at 13:58
  • This is the actual file I am using in my script, I have just removed some data that is useless in this case. – user2847238 Apr 07 '16 at 05:54

1 Answers1

0

check your groovy version, should be fixed by the end of 2011 (https://issues.apache.org/jira/browse/GROOVY-5129)

Pavel Gatnar
  • 3,987
  • 2
  • 19
  • 29