Closed anki006 closed 8 months ago
@anki006 Thanks for bringing this issue up, will look into it.
xml
<color> <color_type>primary</color_type> <value>008E97</value> </color>
may be converted to json
{
"color": {
"color_type": "primary",
"value": "008E97"
},
"#omit-xml-declaration": "yes"
}
Hello @stleary Any update on this issue?
@anki006 I believe this may be related to #826
Pretty sure this is just another case of someone not using the "keep strings" setting in the xml parser
@anki006 After some review - JSON does not recognize hex as a valid type. In this case, the 'e' char is causing the string to be interpreted as a number in scientific notation, which is supported. Agreed, you should be keeping the values as strings.
For example, XML.toJSONObject(str, new XMLParserConfiguration().withKeepStrings(true));
Where str contains the XML to be converted to JSON.
While parsing an XML which has hexadecimal value which starts with number (0-9), for example below: `
`
The equivalent json is formed is:
"color": [ { "color_type": "primary", "value": 8e+97 } ]
However, if the hexadecimal value starts with string, its equivalent json is also a string. `
The equivalent json is formed is:
"color": [ { "color_type": "primary", "value": "fc4c02" } ]`The code fails to handle hexadecimal conversion and creates ambiguity by treating it as number and string both. I assume, if there is ambiguities like this, we need to stick to string rather than converting to number.