mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-02 19:15:27 -04:00
fixed keeping null as string
This commit is contained in:
parent
d7593fb808
commit
3dce55794f
@ -428,6 +428,9 @@ public class XML {
|
||||
config.isKeepNumberAsString()
|
||||
? ((String) token)
|
||||
: obj);
|
||||
} else if (obj == JSONObject.NULL) {
|
||||
jsonObject.accumulate(config.getcDataTagName(),
|
||||
config.isKeepStrings() ? ((String) token) : obj);
|
||||
} else {
|
||||
jsonObject.accumulate(config.getcDataTagName(), stringToValue((String) token));
|
||||
}
|
||||
|
@ -794,6 +794,18 @@ public class XMLConfigurationTest {
|
||||
Util.compareActualVsExpectedJsonObjects(actualJsonOutput,expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* null is "null" when keepStrings == true
|
||||
*/
|
||||
@Test
|
||||
public void testToJSONArray_jsonOutput_null_withKeepString() {
|
||||
final String originalXml = "<root><id>01</id><id>1</id><id>00</id><id>0</id><item id=\"01\"/><title>null</title></root>";
|
||||
final JSONObject expected = new JSONObject("{\"root\":{\"item\":{\"id\":\"01\"},\"id\":[\"01\",\"1\",\"00\",\"0\"],\"title\":\"null\"}}");
|
||||
final JSONObject actualJsonOutput = XML.toJSONObject(originalXml,
|
||||
new XMLParserConfiguration().withKeepStrings(true));
|
||||
Util.compareActualVsExpectedJsonObjects(actualJsonOutput,expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test keepStrings behavior when setting keepBooleanAsString, keepNumberAsString
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user