From f6ca2e43f8dc21055f81ba5282a89288d880050d Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Tue, 2 Apr 2024 15:22:44 +0300 Subject: [PATCH 1/9] Fixes bug in serializer --- CHANGELOG.md | 6 ++++++ .../kiota/serialization/JsonParseNode.java | 13 +++++++------ .../kiota/serialization/JsonParseNodeTests.java | 16 ++++++++++++++++ gradle.properties | 2 +- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46b8c3b8b..ced4410b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +## [1.1.3] - 2024-04-02 + +### Changed + +- Fixes a bug in the seriliazer that would `IllegalStateException` for json arrays in the additional data. + ## [1.1.2] - 2024-03-26 ### Changed diff --git a/components/serialization/json/src/main/java/com/microsoft/kiota/serialization/JsonParseNode.java b/components/serialization/json/src/main/java/com/microsoft/kiota/serialization/JsonParseNode.java index 06a94ab5a..771650ba1 100644 --- a/components/serialization/json/src/main/java/com/microsoft/kiota/serialization/JsonParseNode.java +++ b/components/serialization/json/src/main/java/com/microsoft/kiota/serialization/JsonParseNode.java @@ -163,8 +163,8 @@ public JsonParseNode(@Nonnull final JsonElement node) { } } - private List iterateOnArray(Function fn) { - JsonArray array = currentNode.getAsJsonArray(); + private List iterateOnArray(JsonElement jsonElement, Function fn) { + JsonArray array = jsonElement.getAsJsonArray(); final Iterator sourceIterator = array.iterator(); final List result = new ArrayList<>(); while (sourceIterator.hasNext()) { @@ -182,7 +182,8 @@ private List iterateOnArray(Function fn) { if (currentNode.isJsonNull()) { return null; } else if (currentNode.isJsonArray()) { - return iterateOnArray(itemNode -> getPrimitiveValue(targetClass, itemNode)); + return iterateOnArray( + currentNode, itemNode -> getPrimitiveValue(targetClass, itemNode)); } else throw new RuntimeException("invalid state expected to have an array node"); } @@ -192,7 +193,7 @@ private List iterateOnArray(Function fn) { if (currentNode.isJsonNull()) { return null; } else if (currentNode.isJsonArray()) { - return iterateOnArray(itemNode -> itemNode.getObjectValue(factory)); + return iterateOnArray(currentNode, itemNode -> itemNode.getObjectValue(factory)); } else return null; } @@ -202,7 +203,7 @@ private List iterateOnArray(Function fn) { if (currentNode.isJsonNull()) { return null; } else if (currentNode.isJsonArray()) { - return iterateOnArray(itemNode -> itemNode.getEnumValue(enumParser)); + return iterateOnArray(currentNode, itemNode -> itemNode.getEnumValue(enumParser)); } else throw new RuntimeException("invalid state expected to have an array node"); } @@ -242,7 +243,7 @@ else if (element.isJsonPrimitive()) { return new UntypedObject(propertiesMap); } else if (element.isJsonArray()) { - return new UntypedArray(iterateOnArray(JsonParseNode::getUntypedValue)); + return new UntypedArray(iterateOnArray(element, JsonParseNode::getUntypedValue)); } throw new RuntimeException( diff --git a/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/JsonParseNodeTests.java b/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/JsonParseNodeTests.java index 80464cbc2..bbd3cf694 100644 --- a/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/JsonParseNodeTests.java +++ b/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/JsonParseNodeTests.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.*; import com.google.gson.JsonParser; +import com.microsoft.kiota.serialization.mocks.TestEntity; import com.microsoft.kiota.serialization.mocks.UntypedTestEntity; import org.junit.jupiter.api.Test; @@ -16,6 +17,10 @@ class JsonParseNodeTests { private static final JsonParseNodeFactory _parseNodeFactory = new JsonParseNodeFactory(); private static final String contentType = "application/json"; + + private static final String testJsonString = + "{\"displayName\":\"My Group\",\"id\":\"11111111-1111-1111-1111-111111111111" + + "\",\"members@delta\":[{\"@odata.type\":\"#microsoft.graph.user\",\"id\":\"22222222-2222-2222-2222-222222222222\"}]}"; private static final String testUntypedJson = "{\r\n" + " \"@odata.context\":" @@ -95,6 +100,17 @@ void testInvalidOffsetDateTimeStringThrowsException(final String dateTimeString) } } + @Test + void getEntityWithArrayInAdditionalData() throws UnsupportedEncodingException { + final var rawResponse = new ByteArrayInputStream(testJsonString.getBytes("UTF-8")); + final var parseNode = _parseNodeFactory.getParseNode(contentType, rawResponse); + // Act + var entity = parseNode.getObjectValue(TestEntity::createFromDiscriminatorValue); + assertEquals("11111111-1111-1111-1111-111111111111", entity.getId()); + final var arrayValue = (UntypedArray) entity.getAdditionalData().get("members@delta"); + assertEquals(1, arrayValue.getValue().spliterator().estimateSize()); + } + @Test void GetEntityWithUntypedNodesFromJson() throws UnsupportedEncodingException { final var rawResponse = new ByteArrayInputStream(testUntypedJson.getBytes("UTF-8")); diff --git a/gradle.properties b/gradle.properties index 5be5fc750..8cb2e80e0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,7 +26,7 @@ org.gradle.caching=true mavenGroupId = com.microsoft.kiota mavenMajorVersion = 1 mavenMinorVersion = 1 -mavenPatchVersion = 2 +mavenPatchVersion = 3 mavenArtifactSuffix = #These values are used to run functional tests From 03d9d28d30ea19520ddddf8cd0843dcf3fad80c6 Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Tue, 2 Apr 2024 15:50:07 +0300 Subject: [PATCH 2/9] Bump coverage --- .../serialization/JsonParseNodeTests.java | 7 +++- .../kiota/serialization/mocks/TestEntity.java | 34 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/JsonParseNodeTests.java b/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/JsonParseNodeTests.java index bbd3cf694..3fe648711 100644 --- a/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/JsonParseNodeTests.java +++ b/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/JsonParseNodeTests.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.*; import com.google.gson.JsonParser; +import com.microsoft.kiota.serialization.mocks.MyEnum; import com.microsoft.kiota.serialization.mocks.TestEntity; import com.microsoft.kiota.serialization.mocks.UntypedTestEntity; @@ -19,7 +20,8 @@ class JsonParseNodeTests { private static final String contentType = "application/json"; private static final String testJsonString = - "{\"displayName\":\"My Group\",\"id\":\"11111111-1111-1111-1111-111111111111" + "{\"displayName\":\"My" + + " Group\",\"phones\":[\"+1234567890\"],\"myEnum\":\"VALUE1\",\"enumCollection\":[\"VALUE1\"],\"id\":\"11111111-1111-1111-1111-111111111111" + "\",\"members@delta\":[{\"@odata.type\":\"#microsoft.graph.user\",\"id\":\"22222222-2222-2222-2222-222222222222\"}]}"; private static final String testUntypedJson = "{\r\n" @@ -107,6 +109,9 @@ void getEntityWithArrayInAdditionalData() throws UnsupportedEncodingException { // Act var entity = parseNode.getObjectValue(TestEntity::createFromDiscriminatorValue); assertEquals("11111111-1111-1111-1111-111111111111", entity.getId()); + assertEquals(1, entity.getPhones().size()); + assertEquals(MyEnum.MY_VALUE1, entity.getMyEnum()); + assertEquals(1, entity.getEnumCollection().size()); final var arrayValue = (UntypedArray) entity.getAdditionalData().get("members@delta"); assertEquals(1, arrayValue.getValue().spliterator().estimateSize()); } diff --git a/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/mocks/TestEntity.java b/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/mocks/TestEntity.java index fbe21178d..afc99ebe5 100644 --- a/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/mocks/TestEntity.java +++ b/components/serialization/json/src/test/java/com/microsoft/kiota/serialization/mocks/TestEntity.java @@ -9,7 +9,9 @@ import java.time.LocalDate; import java.time.LocalTime; import java.time.OffsetDateTime; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.function.Consumer; @@ -25,6 +27,16 @@ public void setId(String _id) { this._id = _id; } + private List _phones; + + public List getPhones() { + return _phones; + } + + public void setPhones(List _phones) { + this._phones = new ArrayList(_phones); + } + private String _officeLocation; public String getOfficeLocation() { @@ -85,6 +97,16 @@ public void setMyEnum(MyEnum value) { this._myEnum = value; } + private List _enumCollection; + + public List getEnumCollection() { + return _enumCollection; + } + + public void setEnumCollection(List value) { + this._enumCollection = new ArrayList(value); + } + private OffsetDateTime _createdDateTime; public OffsetDateTime getCreatedDateTime() { @@ -134,11 +156,21 @@ public Map> getFieldDeserializers() { (n) -> { setMyEnum(n.getEnumValue(MyEnum::forValue)); }); + put( + "enumCollection", + (n) -> { + setEnumCollection(n.getCollectionOfEnumValues(MyEnum::forValue)); + }); put( "createdDateTime", (n) -> { setCreatedDateTime(n.getOffsetDateTimeValue()); }); + put( + "phones", + (n) -> { + setPhones(n.getCollectionOfPrimitiveValues(String.class)); + }); } }; } @@ -153,7 +185,9 @@ public void serialize(SerializationWriter writer) { writer.writeLocalTimeValue("startWorkTime", getStartWorkTime()); writer.writeLocalTimeValue("endWorkTime", getEndWorkTime()); writer.writeEnumValue("myEnum", getMyEnum()); + writer.writeCollectionOfEnumValues("enumCollection", getEnumCollection()); writer.writeOffsetDateTimeValue("createdDateTime", getCreatedDateTime()); + writer.writeCollectionOfPrimitiveValues("phones", getPhones()); writer.writeAdditionalData(getAdditionalData()); } From 51d064481afa03838bd553427c77ecd3ca2bac23 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 22:12:43 +0000 Subject: [PATCH 3/9] Bump com.gradle:gradle-enterprise-gradle-plugin Bumps com.gradle:gradle-enterprise-gradle-plugin from 3.16.2 to 3.17. --- updated-dependencies: - dependency-name: com.gradle:gradle-enterprise-gradle-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- components/abstractions/android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/abstractions/android/build.gradle b/components/abstractions/android/build.gradle index 6224550ab..d159fdf4a 100644 --- a/components/abstractions/android/build.gradle +++ b/components/abstractions/android/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath "com.gradle:gradle-enterprise-gradle-plugin:3.16.2" + classpath "com.gradle:gradle-enterprise-gradle-plugin:3.17" classpath "com.android.tools.build:gradle:8.3.1" classpath "com.github.ben-manes:gradle-versions-plugin:0.51.0" } From 5023a18cfe2042f9a244a81ea14ea24d156328a7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 22:27:32 +0000 Subject: [PATCH 4/9] Bump com.gradle:gradle-enterprise-gradle-plugin Bumps com.gradle:gradle-enterprise-gradle-plugin from 3.16.2 to 3.17. --- updated-dependencies: - dependency-name: com.gradle:gradle-enterprise-gradle-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- components/authentication/azure/android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/authentication/azure/android/build.gradle b/components/authentication/azure/android/build.gradle index 02aed9339..ad2d01f9b 100644 --- a/components/authentication/azure/android/build.gradle +++ b/components/authentication/azure/android/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath "com.gradle:gradle-enterprise-gradle-plugin:3.16.2" + classpath "com.gradle:gradle-enterprise-gradle-plugin:3.17" classpath "com.android.tools.build:gradle:8.3.1" classpath "com.github.ben-manes:gradle-versions-plugin:0.51.0" } From 3c2993a3f0f1de06de213e618cb81498d03cdef3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 22:34:24 +0000 Subject: [PATCH 5/9] Bump com.gradle:gradle-enterprise-gradle-plugin Bumps com.gradle:gradle-enterprise-gradle-plugin from 3.16.2 to 3.17. --- updated-dependencies: - dependency-name: com.gradle:gradle-enterprise-gradle-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- components/serialization/text/android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/serialization/text/android/build.gradle b/components/serialization/text/android/build.gradle index 571592d23..c16b0dafc 100644 --- a/components/serialization/text/android/build.gradle +++ b/components/serialization/text/android/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath "com.gradle:gradle-enterprise-gradle-plugin:3.16.2" + classpath "com.gradle:gradle-enterprise-gradle-plugin:3.17" classpath "com.android.tools.build:gradle:8.3.1" classpath "com.github.ben-manes:gradle-versions-plugin:0.51.0" } From 4483f65f7fc88bfa76cbb195cf08ce9c6cc03c30 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 22:37:58 +0000 Subject: [PATCH 6/9] Bump com.gradle:gradle-enterprise-gradle-plugin Bumps com.gradle:gradle-enterprise-gradle-plugin from 3.16.2 to 3.17. --- updated-dependencies: - dependency-name: com.gradle:gradle-enterprise-gradle-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- components/http/okHttp/android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/http/okHttp/android/build.gradle b/components/http/okHttp/android/build.gradle index d7989858a..990fef91e 100644 --- a/components/http/okHttp/android/build.gradle +++ b/components/http/okHttp/android/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath "com.gradle:gradle-enterprise-gradle-plugin:3.16.2" + classpath "com.gradle:gradle-enterprise-gradle-plugin:3.17" classpath "com.android.tools.build:gradle:8.3.1" classpath "com.github.ben-manes:gradle-versions-plugin:0.51.0" } From 8cc79a075fb0ff7227b95f8aac3d047d1249d6b7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 22:55:36 +0000 Subject: [PATCH 7/9] Bump com.gradle:gradle-enterprise-gradle-plugin Bumps com.gradle:gradle-enterprise-gradle-plugin from 3.16.2 to 3.17. --- updated-dependencies: - dependency-name: com.gradle:gradle-enterprise-gradle-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- components/serialization/form/android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/serialization/form/android/build.gradle b/components/serialization/form/android/build.gradle index 571592d23..c16b0dafc 100644 --- a/components/serialization/form/android/build.gradle +++ b/components/serialization/form/android/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath "com.gradle:gradle-enterprise-gradle-plugin:3.16.2" + classpath "com.gradle:gradle-enterprise-gradle-plugin:3.17" classpath "com.android.tools.build:gradle:8.3.1" classpath "com.github.ben-manes:gradle-versions-plugin:0.51.0" } From db285ef6d7e8251e9fee60cef3658c0d0b15da33 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 22:55:37 +0000 Subject: [PATCH 8/9] Bump com.gradle:gradle-enterprise-gradle-plugin Bumps com.gradle:gradle-enterprise-gradle-plugin from 3.16.2 to 3.17. --- updated-dependencies: - dependency-name: com.gradle:gradle-enterprise-gradle-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- components/serialization/json/android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/serialization/json/android/build.gradle b/components/serialization/json/android/build.gradle index 571592d23..c16b0dafc 100644 --- a/components/serialization/json/android/build.gradle +++ b/components/serialization/json/android/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath "com.gradle:gradle-enterprise-gradle-plugin:3.16.2" + classpath "com.gradle:gradle-enterprise-gradle-plugin:3.17" classpath "com.android.tools.build:gradle:8.3.1" classpath "com.github.ben-manes:gradle-versions-plugin:0.51.0" } From 90cd560e865b5fd691c15abe5f30fe7d41177ba1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 22:59:46 +0000 Subject: [PATCH 9/9] Bump com.gradle:gradle-enterprise-gradle-plugin Bumps com.gradle:gradle-enterprise-gradle-plugin from 3.16.2 to 3.17. --- updated-dependencies: - dependency-name: com.gradle:gradle-enterprise-gradle-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- components/serialization/multipart/android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/serialization/multipart/android/build.gradle b/components/serialization/multipart/android/build.gradle index 571592d23..c16b0dafc 100644 --- a/components/serialization/multipart/android/build.gradle +++ b/components/serialization/multipart/android/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath "com.gradle:gradle-enterprise-gradle-plugin:3.16.2" + classpath "com.gradle:gradle-enterprise-gradle-plugin:3.17" classpath "com.android.tools.build:gradle:8.3.1" classpath "com.github.ben-manes:gradle-versions-plugin:0.51.0" }