We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The introducing of #240 brought in an error that it cannot handle simple XML without attributes conversion correctly.
This CR is to improve XML to JSON convert logic to handle XML with or without attributes correctly.
<root> <parent> <child>123</child> </parent> </root>
converted ($.convert(xmlDoc).to(JSONObject.class)) into
$.convert(xmlDoc).to(JSONObject.class)
{ "parent": { "child": 123 } }
<root> <parent> <child>123</child> </parent> <parent> <child>456</child> </parent> </root>
converted into
JSON without MERGE_MAP hint:
{ "parent": [ { "child": 123 }, { "child": 456 } ] }
JSON with MERGE_MAP hint ($.convert(xmlDoc).hint(XmlToJson.HINT_MERGE_MAP).to(JSONObject.class)) turned on:
$.convert(xmlDoc).hint(XmlToJson.HINT_MERGE_MAP).to(JSONObject.class)
{ "parent": { "child": [123, 456] } }
<root> <parent> <child>123</child> </parent> <parent> <child>456</child> </parent> <parent2> <child>789</child> </parent2> <someone>abc</someone> </root>
{ "parent": [ { "child": 123 }, { "child": 456 } ], "parent2": { "child": 789 }, "someone": "abc" }
JSON with MERGE_MAP hint turned on
{ "parent": { "child": [123, 456] }, "parent2": { "child": 789 }, "someone": "abc" }
<root> <parent> <child value="123"/> </parent> </root>
{ "parent": { "child": { "value": 123 } } }
<root> <parent> <child value="123">abc</child> </parent> </root>
{ "parent": { "child": { "value": 123, "innerValue": "abc" } } }
OSGL tool XML to JSON convert tool require at least one ELEMENT type node inside the root node, otherwise it returns an empty JSONObject.
E.g. converting the following xml document will return an empty JSONObject:
<root>abc</root>
The text was updated successfully, but these errors were encountered:
Improve XML to JSON convert logic #243
59e73f7
cfbe21c
Refer: https://github.com/osglworks/java-tool/blob/master/src/test/java/org/osgl/util/XMLTest.java#L32
Sorry, something went wrong.
greenlaw110
No branches or pull requests
The introducing of #240 brought in an error that it cannot handle simple XML without attributes conversion correctly.
This CR is to improve XML to JSON convert logic to handle XML with or without attributes correctly.
Case 1.1 - simple XML without attributes
converted (
$.convert(xmlDoc).to(JSONObject.class)
) intoCase 1.2 - simple XML list without attributes
converted into
JSON without MERGE_MAP hint:
JSON with MERGE_MAP hint (
$.convert(xmlDoc).hint(XmlToJson.HINT_MERGE_MAP).to(JSONObject.class)
) turned on:Case 1.3 - simple mixed XML list without attributes
converted into
JSON without MERGE_MAP hint:
JSON with MERGE_MAP hint turned on
Case 2.1 - XML with attributes and no text
converted into
Case three - XML with attributes and value
converted into
Note
OSGL tool XML to JSON convert tool require at least one ELEMENT type node inside the root node, otherwise it returns an empty JSONObject.
E.g. converting the following xml document will return an empty JSONObject:
The text was updated successfully, but these errors were encountered: