Reputation: 75
This should be a simple issue but I just couldn't find anything on the Internet. Here is the JSON string
{"ratio":2.714,"daily":161.0,"userId":811032853,"topic":"#GOP2012","gender":"Unknow"}
Then when I do mapper.readValue(*theString*,*theClass.class*)
, all the numbers after the decimal point are lost. For the example above, I just got 2.0 for ratio.
The version of jackson I'm using is 1.9.9, which should be the latest version.
Does this happen to anyone else as well? Thanks everyone :)
The theClass is just a class that holds all these variables. The type of ratio is double.
Upvotes: 3
Views: 2387
Reputation: 116572
I would suspect something odd with class definition. Jackson does not truncate double values, beyond the usual caveats with binary floating point notations (i.e. if you wanted to avoid any rounding errors, you should use BigDecimal
etc), which are not enough to cause problems like this.
So it would be useful to see definition of theClass
. If truncation does occur the way explained, it would definitely be a bug.
Upvotes: 1
Reputation: 33544
I have not worked with JackSon, but can you somehow try something like this....
DecimalFormat df = new DecimalFormat("#.###");
df.format(doubleValue);
Upvotes: 0