Skip to content

Converting strings to other types can change values #69

Description

@yaccob

Hi Douglas

The attempt to guess the type of a text node or an attribute value may change the type which may be unintended. If the intended type is a string, "01" is not equal with "1". So operations change values which can cause unwanted effects.
Furthermore the behavior is not consistent: "00" remains unchanged (remains a String) while "01" is converted to the number 1 as you can see in the sample below.
Also automatic conversion to boolean might have unwanted effects. Imagine the title of a book's chapter is "True" - intentionally with upper case "T". As far as I could see currently I am not able to convert this title to Json without implicitly changing it to a boolean and therefore losing information.

Sample:

xml:
<root>
  <id>01</id>
  <id>1</id>
  <id>00</id>
  <id>0</id>
  <title>True</title>
</root>

code:
println org.json.JSONML.toJSONArray(xml)

output:
["root",["id",1],["id",1],["id","00"],["id",0],["title",true]]

I would suggest to either change this or at least to add an option to control the behavior in a static way. (e.g. adding a non-final static boolean field KEEP_STRINGS which can be set to true)

Best regards,
yaccob

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