File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 */
You can’t perform that action at this time.
0 commit comments