I have a Get API which returns a JSON. The format expected is:
{
"value1": "123.00",
"value2": "23.00"
}
These values are BigDecimal in the object:
public class Result{
BigDecimal value1;
BigDecimal value2;
// getters and setters
}
Now, when the request is made, I create the Result object and populate these values as BigDecimal, create a list and return. The response I received is:
{
"value1": 123.00,
"value2": 23.00
}
The values are correct but are not strings. How can I make them strings?
I know we can convert BigDecimal to String but I have object with BigDecimal fields only and I can't populate String values to it.
Finally, this is how the list is made:
List<MyObj> obj = Arrays.stream(myObj).collect(Collectors.toList());
Result result = new Result();
obj.forEach(t -> t.mergeToResult(result)); // mergeToResults does all the population like result.setValue1(new BigDecimal(123.00))
return result;