sayonatinnofied / rest-client

Automatically exported from code.google.com/p/rest-client
Apache License 2.0
0 stars 0 forks source link

"Indent JSON" corrupts results with many decimals #191

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
## What steps will reproduce the problem?
1. Make a call resulting in result with high precision (many decimals)
2. Right-click, select Indent->Indent JSON
3. The result will be different (erroneously truncated/rounded)

## What is the expected output? What do you see instead?
The case that got our attention returned

[{"date":"2013-11-18","performance":1.015786164055542498,"totalValue":43903.53}]

After indentation it read

[ {
  "date" : "2013-11-18",
  "performance" : 1.0157861640555426,
  "totalValue" : 43903.53
} ]

Note the error introduced at the end of "performance".

## What version of the product are you using? On what operating system?
RESTClient 3.2.1 on Windows

## Please provide any additional information below.
Perhaps you internally use Double for handling decimal values? In that case a 
switch to BigDecimal would solve the issue.

Original issue reported on code.google.com by Jan.Ko...@gmail.com on 20 Nov 2013 at 1:54

GoogleCodeExporter commented 8 years ago
The remedy would probably be to add

    mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);

to JSONUtil.

If you want to do some more, you might add a static mapper and a static 
initialization with something like:  

        // Object mappers are thread safe and can be reused as long as they don't need reconfiguration
        objectMapper = new ObjectMapper();
        objectMapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);

Original comment by Jan.Ko...@gmail.com on 20 Nov 2013 at 2:41

GoogleCodeExporter commented 8 years ago
Thanks for reporting with a solution :)

Fixed.

Original comment by subwiz on 20 Nov 2013 at 6:34