Open
Description
precision loss
When using the HttpService of web3j to call the sendBatch method, if the returned data contains a float type, you may encounter precision loss issues.
Steps To Reproduce
Deserializing like HttpService
@Test
public void test2() {
ObjectMapper mapper = new ObjectMapper();
String json = """
{"balance":209338520.59559551,"received":209338520.59559551,"immature":0.00000000}
""";
String jsonArray = """
[{"balance":209338520.59559551,"received":209338520.59559551,"immature":0.00000000}]
""";
try {
var tree = mapper.readTree(json);
var balance = mapper.treeToValue(tree, OriginalAddressRangeBalance2.class);
System.out.println(balance);
ArrayNode nodes = (ArrayNode) mapper.readTree(jsonArray);
List<OriginalAddressRangeBalance2> balances = new ArrayList<>();
for (int i = 0; i < nodes.size(); i++) {
var b = mapper.treeToValue(nodes.get(i), OriginalAddressRangeBalance2.class);
balances.add(b);
}
System.out.println(balances);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class OriginalAddressRangeBalance2 {
private BigDecimal balance;
private BigDecimal received;
private BigDecimal immature;
}
### Expected behavior
Output:
UtxoClientTest.OriginalAddressRangeBalance2(balance=209338520.59559551, received=209338520.59559551, immature=0)
[UtxoClientTest.OriginalAddressRangeBalance2(balance=209338520.59559551, received=209338520.59559551, immature=0)]
### Actual behavior
Output:
UtxoClientTest.OriginalAddressRangeBalance2(balance=209338520.5955955, received=209338520.5955955, immature=0.0)
[UtxoClientTest.OriginalAddressRangeBalance2(balance=209338520.5955955, received=209338520.5955955, immature=0.0)]
## Environment
_Describe the environment in which the issue occurs_
- Web3j version: 4.8.6
- Java version: jdk17, Zulu17.52+17-CA (build 17.0.12+7-LTS)
- Operating System: macos 15.0.1 (24A348)