简体   繁体   中英

Spring rest api why does data type getting changed in the response from rest api call

There is a function which returns a responseEntitiy with List of arraylist of objects

return new ResponseEntity<>(apiResponse, HttpStatus.OK);

for example,

list of following arraylist,

row1{1,353543.23,100L}
row1{2,232.56,110L}.....

while debugging I get to know that at this stage the response has field values as BigDecimal or long in apiResponse object, its a list of arraylist of objects(objects are of type Bigdecimal/long), but when it enters in the calling function I see the response, these BigDecimal or long values have converted/considered as Integer/double depending upon there is decimal in the number or not, this is happening for small numbers. I couldn't understand where and why it is deciding its own, to change the data types while transmitting.

Because of this the function where i'm trying to handle this response gives an error of can not convert Integer to Double/long, ideally because bigdecimal and long values are being sent I expect these values come as is, retaining its data type but its not the case

By default spring uses jackson as a serializer, so you could check whether the issues happen with the version you use right now:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM