Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precision lossed when using sendBatch #2141

Open
FineKe opened this issue Jan 16, 2025 · 0 comments
Open

Precision lossed when using sendBatch #2141

FineKe opened this issue Jan 16, 2025 · 0 comments
Labels
bug A bug in behaviour or functionality

Comments

@FineKe
Copy link

FineKe commented Jan 16, 2025

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)


@FineKe FineKe added the bug A bug in behaviour or functionality label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug in behaviour or functionality
Projects
None yet
Development

No branches or pull requests

1 participant