diff --git a/src/main/java/ortus/boxlang/modules/wddx/util/WDDXUtil.java b/src/main/java/ortus/boxlang/modules/wddx/util/WDDXUtil.java index b45a9f8..9ffcdcf 100644 --- a/src/main/java/ortus/boxlang/modules/wddx/util/WDDXUtil.java +++ b/src/main/java/ortus/boxlang/modules/wddx/util/WDDXUtil.java @@ -24,6 +24,7 @@ import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.context.IBoxContext; import ortus.boxlang.runtime.dynamic.casters.ArrayCaster; +import ortus.boxlang.runtime.dynamic.casters.BooleanCaster; import ortus.boxlang.runtime.dynamic.casters.DateTimeCaster; import ortus.boxlang.runtime.dynamic.casters.GenericCaster; import ortus.boxlang.runtime.dynamic.casters.IntegerCaster; @@ -95,6 +96,9 @@ public static Object deserializeObject( XML obj ) { case "array" : { return obj.getXMLChildrenAsList().stream().map( WDDXUtil::deserializeObject ).collect( BLCollector.toArray() ); } + case "boolean" : { + return BooleanCaster.cast( obj.getXMLAttributes().get( Key.value ) ); + } default : { return GenericCaster.cast( context, obj.getXMLText(), obj.getNode().getNodeName() ); } @@ -126,6 +130,11 @@ public static String serializeObject( Object obj ) { if ( obj instanceof Query ) { return serializeQuery( QueryCaster.cast( obj ) ); } + // Booleans have a different pattern, in that they do not have an outer wrapper + if ( obj instanceof Boolean ) { + return ""; + } + Key classKey = Key.of( StringUtil.lcFirst( obj.getClass().getSimpleName() ) ); String serialization = "<" + classKey.getName() + ( obj instanceof Array ? " length=\"" + ArrayCaster.cast( obj ).size() + "\"" : "" ) + ">"; if ( obj instanceof IStruct ) { diff --git a/src/test/java/ortus/boxlang/modules/wddx/util/WDDXUtilTest.java b/src/test/java/ortus/boxlang/modules/wddx/util/WDDXUtilTest.java index 92ae7fa..f0ed608 100644 --- a/src/test/java/ortus/boxlang/modules/wddx/util/WDDXUtilTest.java +++ b/src/test/java/ortus/boxlang/modules/wddx/util/WDDXUtilTest.java @@ -26,6 +26,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import ortus.boxlang.runtime.dynamic.casters.StructCaster; import ortus.boxlang.runtime.scopes.Key; import ortus.boxlang.runtime.types.Array; import ortus.boxlang.runtime.types.DateTime; @@ -40,10 +41,11 @@ public class WDDXUtilTest { @Test void testSerializeStruct() { IStruct test = Struct.of( - "foo", "bar" + "foo", "bar", + "isWDDX", true ); String wddx = WDDXUtil.serializeObject( test ); - assertEquals( "bar", wddx ); + assertEquals( "bar", wddx ); } @DisplayName( "Test array serialization" ) @@ -105,12 +107,24 @@ void testParse() { bar + + + """.trim(); Object result = WDDXUtil.parse( wddx ); assertTrue( result instanceof IStruct ); + IStruct deserialized = StructCaster.cast( result ); + assertTrue( deserialized.containsKey( Key.of( "flea" ) ) ); + assertTrue( deserialized.get( Key.of( "flea" ) ) instanceof Array ); + assertTrue( deserialized.containsKey( Key.of( "flah" ) ) ); + assertTrue( deserialized.get( Key.of( "flah" ) ) instanceof IStruct ); + assertTrue( deserialized.containsKey( Key.of( "foo" ) ) ); + assertTrue( deserialized.get( Key.of( "foo" ) ) instanceof String ); + assertTrue( deserialized.containsKey( Key.of( "isWDDX" ) ) ); + assertTrue( deserialized.get( Key.of( "isWDDX" ) ) instanceof Boolean ); } } \ No newline at end of file