Skip to content

fix(json): preserve falsy root values in serialized content - #743

Merged
Vincent Biret (baywet) merged 4 commits into
microsoft:mainfrom
Shubham-Padkonde:fix/json-falsy-root-values
Sep 21, 2026
Merged

Vincent Biret (baywet) merged 4 commits into
microsoft:mainfrom
Shubham-Padkonde:fix/json-falsy-root-values

Conversation

@Shubham-Padkonde

@Shubham-Padkonde Shubham Padkonde (Shubham-Padkonde) commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Overview

Root JSON values false, 0, 0.0, "" and [] currently serialize as {}, including through RequestInformation.set_content_from_scalar. Explicit root null also needs to be distinguished from an unset writer. Track root presence separately from the payload, preserve it for composed objects, use it for mixed-root/property validation, and reset it after serialization.

Related Issue

Fixes #742

Testing Instructions

From packages/serialization/json, install requirements-dev.txt and run pytest.

  • 148 package tests pass on Windows/Python 3.12.
  • 28 added cases cover root round trips, writer reuse, mixed-root/property rejection, actual RequestInformation content, and composed-object null serialization. The original falsy-root regressions produced 16 failures before the initial fix; both added root-null cases failed before the review follow-up.
  • Mypy (6 source files), YAPF and isort checks pass. The repository's pylint command exits successfully with 10.00/10, while reporting the existing unrecognized suggestion-mode configuration option.

Notes

AI-assisted implementation and testing. The full multi-package and Python-version CI matrix was not run locally. This starts from main and is independent of #741, which fixes empty property names.

Comment thread packages/serialization/json/tests/unit/test_root_values.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Root null values remain indistinguishable from an unset writer state.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes JSON serialization of falsy root values and adds regression coverage.

Changes:

  • Preserves falsy root values during serialization.
  • Adds tests for root values, mixed roots, writer reuse, and request content.
File Summary
packages/​serialization/​json/​tests/​unit/​test_root_values.py Adds regression tests for root values and request content.
packages/​serialization/​json/​kiota_serialization_json/​json_serialization_writer.py Updates root-value serialization and validation logic.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/serialization/json/kiota_serialization_json/json_serialization_writer.py Outdated
@Shubham-Padkonde

Copy link
Copy Markdown
Contributor Author

Addressed the root-null finding by tracking root presence separately from its payload, including composed-object serialization, and clearing that state after serialization. The new root-null cases failed on the previous implementation; all 148 JSON tests now pass, along with mypy, YAPF, isort and the repository's pylint command (exit 0; existing suggestion-mode configuration diagnostic remains).

The last two lines in the round-trip test verify writer reuse: after serializing a root value, writing a named property must succeed without stale root state causing an invalid mixed-root error. I added a comment explaining that purpose. Agent-assisted update.

Comment thread packages/serialization/json/kiota_serialization_json/json_serialization_writer.py Outdated
@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Sep 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified, and all reviewed changes have regression coverage.

Review effort: Lite
Findings: None

Resolved since last review (1)

@sonarqubecloud

Copy link
Copy Markdown

@baywet
Vincent Biret (baywet) merged commit 8336f05 into microsoft:main Sep 21, 2026
53 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress 🚧 to Done ✔️ in Kiota Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

JSON serializer replaces falsy root values with an empty object

3 participants