Skip to content

Commit 8e65eaa

Browse files
authored
Merge pull request #968 from marilynel/master
Update keepStrings behavior to reflect changes in keepBooleanAsString, keepNumberAsString
2 parents 2e9ad6f + 74439cf commit 8e65eaa

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/main/java/org/json/XMLParserConfiguration.java

+3
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ protected XMLParserConfiguration clone() {
224224
@Override
225225
public XMLParserConfiguration withKeepStrings(final boolean newVal) {
226226
XMLParserConfiguration newConfig = this.clone();
227+
newConfig.keepStrings = newVal;
227228
newConfig.keepNumberAsString = newVal;
228229
newConfig.keepBooleanAsString = newVal;
229230
return newConfig;
@@ -241,6 +242,7 @@ public XMLParserConfiguration withKeepStrings(final boolean newVal) {
241242
public XMLParserConfiguration withKeepNumberAsString(final boolean newVal) {
242243
XMLParserConfiguration newConfig = this.clone();
243244
newConfig.keepNumberAsString = newVal;
245+
newConfig.keepStrings = newConfig.keepBooleanAsString && newConfig.keepNumberAsString;
244246
return newConfig;
245247
}
246248

@@ -256,6 +258,7 @@ public XMLParserConfiguration withKeepNumberAsString(final boolean newVal) {
256258
public XMLParserConfiguration withKeepBooleanAsString(final boolean newVal) {
257259
XMLParserConfiguration newConfig = this.clone();
258260
newConfig.keepBooleanAsString = newVal;
261+
newConfig.keepStrings = newConfig.keepBooleanAsString && newConfig.keepNumberAsString;
259262
return newConfig;
260263
}
261264

src/test/java/org/json/junit/XMLConfigurationTest.java

+25
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,31 @@ public void testToJSONArray_jsonOutput_withKeepBooleanAsString() {
794794
Util.compareActualVsExpectedJsonObjects(actualJsonOutput,expected);
795795
}
796796

797+
/**
798+
* Test keepStrings behavior when setting keepBooleanAsString, keepNumberAsString
799+
*/
800+
@Test
801+
public void test_keepStringBehavior() {
802+
XMLParserConfiguration xpc = new XMLParserConfiguration().withKeepStrings(true);
803+
assertEquals(xpc.isKeepStrings(), true);
804+
805+
xpc = xpc.withKeepBooleanAsString(true);
806+
xpc = xpc.withKeepNumberAsString(false);
807+
assertEquals(xpc.isKeepStrings(), false);
808+
809+
xpc = xpc.withKeepBooleanAsString(false);
810+
xpc = xpc.withKeepNumberAsString(true);
811+
assertEquals(xpc.isKeepStrings(), false);
812+
813+
xpc = xpc.withKeepBooleanAsString(true);
814+
xpc = xpc.withKeepNumberAsString(true);
815+
assertEquals(xpc.isKeepStrings(), true);
816+
817+
xpc = xpc.withKeepBooleanAsString(false);
818+
xpc = xpc.withKeepNumberAsString(false);
819+
assertEquals(xpc.isKeepStrings(), false);
820+
}
821+
797822
/**
798823
* JSON string cannot be reverted to original xml.
799824
*/

0 commit comments

Comments
 (0)