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

Strings Starting with '0' and Decimal Numbers Incorrectly Converted During XML to JSON Transformation #905

Closed
Justsvetoslavov opened this issue Sep 9, 2024 · 2 comments

Comments

@Justsvetoslavov
Copy link

Justsvetoslavov commented Sep 9, 2024

This issue is similar to the previously resolved issue #826, which addressed the regression where strings starting with a '0' were incorrectly converted to integers. (fixed, as of 20240303, as noted in #868)

However, this new issue concerns decimal numbers that start with a '0', which are still being converted incorrectly in the latest version of the library.

XML

<datatypes>
    <data1>012345.6789</data1>
    <data2>0123456789</data2>
</datatypes>

we use:

JSONObject o = XML.toJSONObject(xml); // keep strings false

Output (on v20240303):

12345.6789 // leading zero omitted
0123456789

While issue #826 resolved the problem of handling integers starting with '0', this particular edge case with decimal numbers was not addressed. As a result, the current behavior strips the leading zero from the decimal number, converting 012345.6789 into 12345.6789, which is not the expected behavior in our case.

It seems there is a mismatch in behavior between how the library handles integer strings and decimal string numbers starting with '0'. Is it possible to handle decimal numbers in a way that preserves the leading zeros as part of the string, without requiring keepStrings=true, which would otherwise undesirably affect the conversion of other data types like booleans and integers?

Thank you for your attention to this issue.

@Justsvetoslavov
Copy link
Author

As this has always been working like this and will be a breaking change, I believe the best option here is to handle it on our side.

@stleary
Copy link
Owner

stleary commented Sep 10, 2024

@Justsvetoslavov This project tries to offer more flexibility for XML/JSON transformations. Feel free to reopen this issue if you would like this specific behavior addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants