Skip to content

Strings that are valid numbers in scientific notation get transformed when converting XML into JSON #230

Description

@oleg-gr

If you have a string in your XML, that also happens to be a valid number in scientific notation, it will be transformed into a java representation of that number when XML is transformed into JSONObject:

XML.toJSONObject("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
        "<str1>045e5000</str1>\n" +
        "<str2>45e5000</str2>\n" +
        "<str3>045e50</str3>\n" +
        "<str4>45e5</str4>");

will return

{"str1":"045e5000","str4":4500000,"str3":4.5E51,"str2":"45e5000"}

I understand that vanilla XML doesn't have a way to define types, but I still think this is a very unpredictable behavior. I am not sure how to solve it. Possibly, do not convert e notations and leave them as strings?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions