From 792c77637104cf610173dfb937dab3f228c903ff Mon Sep 17 00:00:00 2001 From: meywood <105049338+meywood@users.noreply.github.com> Date: Mon, 5 Feb 2024 17:10:00 +0000 Subject: [PATCH] issues/200 - Fixed stream matchers for inversion of unserializable to serializable --- .../sdk/model/clvalue/cltype/CLTypeList.java | 2 +- .../sdk/model/clvalue/cltype/CLTypeMap.java | 2 +- .../model/clvalue/cltype/CLTypeOption.java | 2 +- .../model/clvalue/cltype/CLTypeTuple1.java | 2 +- .../model/clvalue/cltype/CLTypeTuple2.java | 2 +- .../model/clvalue/cltype/CLTypeTuple3.java | 2 +- .../sdk/model/clvalue/NestedAnyTest.java | 35 ++++++++++++++++++- 7 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeList.java b/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeList.java index e72d1baae..018a21bf7 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeList.java +++ b/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeList.java @@ -54,7 +54,7 @@ public void setListType(AbstractCLType listType) { @Override public boolean isDeserializable() { - return getChildTypes().stream().anyMatch(childType -> { + return getChildTypes().stream().allMatch(childType -> { if (childType instanceof CLTypeAny) { return false; } else { diff --git a/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeMap.java b/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeMap.java index a2bbffcb7..01c158e43 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeMap.java +++ b/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeMap.java @@ -36,7 +36,7 @@ public boolean isDeserializable() { // The map contains an 'Any' type therefore cannot be deserialized return false; } else if (getKeyValueTypes().valueType instanceof AbstractCLTypeWithChildren) { - return getChildTypes().stream().anyMatch(childType -> { + return getChildTypes().stream().allMatch(childType -> { if (childType instanceof CLTypeAny) { return false; } else { diff --git a/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeOption.java b/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeOption.java index 849c9d7c0..cddbb42b0 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeOption.java +++ b/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeOption.java @@ -55,6 +55,6 @@ public void setOptionType(AbstractCLType listType) { @Override public boolean isDeserializable() { - return getOptionType().isDeserializable() || getChildTypes().stream().anyMatch(AbstractCLType::isDeserializable); + return getOptionType().isDeserializable() || getChildTypes().stream().allMatch(AbstractCLType::isDeserializable); } } diff --git a/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeTuple1.java b/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeTuple1.java index f4596eb46..506a8da56 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeTuple1.java +++ b/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeTuple1.java @@ -37,6 +37,6 @@ protected List getChildTypeObjects() { @Override public boolean isDeserializable() { - return getChildTypes().stream().anyMatch(AbstractCLType::isDeserializable); + return getChildTypes().stream().allMatch(AbstractCLType::isDeserializable); } } diff --git a/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeTuple2.java b/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeTuple2.java index 00903b9d4..67061e3dd 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeTuple2.java +++ b/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeTuple2.java @@ -37,6 +37,6 @@ protected List getChildTypeObjects() { @Override public boolean isDeserializable() { - return getChildTypes().stream().anyMatch(AbstractCLType::isDeserializable); + return getChildTypes().stream().allMatch(AbstractCLType::isDeserializable); } } diff --git a/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeTuple3.java b/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeTuple3.java index 2eb276239..8eab6ec59 100644 --- a/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeTuple3.java +++ b/src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeTuple3.java @@ -37,6 +37,6 @@ protected List getChildTypeObjects() { @Override public boolean isDeserializable() { - return getChildTypes().stream().anyMatch(AbstractCLType::isDeserializable); + return getChildTypes().stream().allMatch(AbstractCLType::isDeserializable); } } diff --git a/src/test/java/com/casper/sdk/model/clvalue/NestedAnyTest.java b/src/test/java/com/casper/sdk/model/clvalue/NestedAnyTest.java index 98600a535..07d55dba1 100644 --- a/src/test/java/com/casper/sdk/model/clvalue/NestedAnyTest.java +++ b/src/test/java/com/casper/sdk/model/clvalue/NestedAnyTest.java @@ -74,7 +74,7 @@ void readStepEventWithMapContainingAnyValue() throws Exception { } @Test - public void nestedMapWithoutAny() throws Exception { + public void nestedEmptyMapiWithoutAny() throws Exception { final String json = " {\n" + " \"cl_type\": {\n" + @@ -93,4 +93,37 @@ public void nestedMapWithoutAny() throws Exception { assertThat(clValueMap.getBytes(), is("00000000")); } + @Test + void nestedListWithAny() throws Exception { + + final String json = " {\n" + + " \"cl_type\": {\n" + + " \"List\": \"Any\"\n" + + " },\n" + + " \"bytes\": \"00000000\",\n" + + " \"parsed\": null\n" + + "}"; + + final CLValueList clValueList = (CLValueList) new ObjectMapper().readValue(json, AbstractCLValue.class); + assertThat(clValueList, is(notNullValue())); + assertThat(clValueList.getClType().isDeserializable(), is(false)); + assertThat(clValueList.getBytes(), is("00000000")); + } + + @Test + void nestedListWithoutAny() throws Exception { + + final String json = " {\n" + + " \"cl_type\": {\n" + + " \"List\": \"U256\"\n" + + " },\n" + + " \"bytes\": \"00000000\",\n" + + " \"parsed\": null\n" + + "}"; + + final CLValueList clValueList = (CLValueList) new ObjectMapper().readValue(json, AbstractCLValue.class); + assertThat(clValueList, is(notNullValue())); + assertThat(clValueList.getClType().isDeserializable(), is(true)); + assertThat(clValueList.getBytes(), is("00000000")); + } }