1

We are using compile net.sf.json-lib:json-lib:2.4:jdk15

String requestBody =     {"resconfirmsvid":28,"reservationno":"H0028W090718","component":"Hotel","partnerid":2,"total":169002.15,"internalnote":"","currencycode":"USD","history":[{"id":"0","payment_type":"Payment","payment_method":"Cash","date":"2019-10-30","refnumber":"012525TRTY","amount":160000,"currency":"USD","component":"Hotel","resconfirmsvid":28}]}

requestBody = URLDecoder.decode(requestBody, "UTF-8");
JSONObject request = JSONObject.fromObject(requestBody);

Then request object as follows,

request = {"resconfirmsvid":28,"reservationno":"H0028W090718","component":"Hotel","partnerid":2,"total":169002.16,"internalnote":"","currencycode":"USD","history":[{"id":"0","payment_type":"Payment","payment_method":"Cash","date":"2019-10-30","refnumber":"012525TRTY","amount":160000,"currency":"USD","component":"Hotel","resconfirmsvid":28}]}

After convert json string into json object using fromObject "total" value changed to 169002.16 from 169002.15

AsithaL
  • 59
  • 1
  • 1
  • 8

2 Answers2

3

I got a same issue, when i used net.sf.json-lib for coverting json string into Json object.once i used the below gradle version
compile 'net.sf.json-lib:json-lib:2.3:jdk15' issue was fixed sucessfully.

hazzy1986
  • 103
  • 6
  • When you downgrade the jar it will effected following issue fixes and new enhancement. Please consider this before downgrade the jar. http://json-lib.sourceforge.net/changes-report.html#a2.4 – Thusitha Indunil Oct 30 '19 at 07:17
1

JSON does not specify a precision for decimal numbers. That's why it is recommended to use strings for decimal numbers instead.

Source: Why would you use a string in JSON to represent a decimal number - dthorpe

Babyburger
  • 1,730
  • 3
  • 19
  • 32