Repository navigation
fix: serialize Gson elements in additional data - #2188
Merged
Vincent Biret (baywet) merged 1 commit intoSep 21, 2026
Merged
Vincent Biret (baywet) merged 1 commit into
Vincent Biret (baywet) merged 1 commit into
Conversation
Shubham Padkonde (Shubham-Padkonde)
requested a review
from a team
as a code owner
September 21, 2026 07:07
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The change is narrowly scoped, addresses the reported failure mode directly, and includes targeted regression tests covering key JSON element variants.
Review effort: Lite
Findings: None
What changed in this PR
This PR fixes serialization of Gson JsonElement values stored in additionalData by handling them explicitly in JsonSerializationWriter before the generic Iterable/reflection fallback paths, preventing invalid JSON output and IllegalStateException: Dangling name.
Changes:
- Add a dedicated
JsonElementserialization path inJsonSerializationWriter.writeAnyValue. - Add parameterized regression coverage for
JsonObject,JsonArray, primitives,null, large integers, escaping, and empty containers in additional-data serialization.
| File | Description |
|---|---|
| components/serialization/json/src/main/java/com/microsoft/kiota/serialization/JsonSerializationWriter.java | Recognizes JsonElement in writeAnyValue and serializes it via Gson’s JsonElement adapter to avoid reflection/iterable fallbacks. |
| components/serialization/json/src/test/java/com/microsoft/kiota/serialization/JsonSerializationWriterTests.java | Adds a parameterized regression test validating correct round-trip serialization of JsonElement values placed in additionalData. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Vincent Biret (baywet)
approved these changes
Sep 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1388.
Gson JsonObject values in additional data currently reach the reflection fallback, which writes a property name without a value and then fails with
IllegalStateException: Dangling name. JsonPrimitive and JsonNull values fail similarly; JsonArray takes the Iterable path, where its nonempty elements encounter the same problem. This prevents serializing custom security attributes as described in microsoftgraph/msgraph-sdk-java#2063.Recognize JsonElement before the generic Iterable/reflection paths and write it through the writer's existing Gson instance and public JsonElement adapter. This covers objects, arrays, primitives, and JSON null without reflecting over Gson implementation classes or converting numbers through double.
Eight regression cases exercise additional-data serialization, including nested objects/arrays/nulls, escaped strings, a large integer, and empty containers. Seven fail on the original implementation; the empty-array control already passed. All pass with the fix.
Validation: JDK 21 and Gradle 9.7.1 (the repository wrapper version):
spotlessApplyandbuild: 38 tests pass, including Spotless and SpotBugs checks.build -Pjava8=truewith a Java 8 toolchain supplied for compatibility projects.No live Microsoft Graph calls or Android build were run.
AI assistance: Codex assisted with the reproduction, implementation, and local validation. No separate human review is claimed.