fix(json): preserve falsy root values in serialized content - #743
Vincent Biret (baywet) merged 4 commits into
Conversation
There was a problem hiding this comment.
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
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.
|
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. |
|




Overview
Root JSON values
false,0,0.0,""and[]currently serialize as{}, including throughRequestInformation.set_content_from_scalar. Explicit rootnullalso 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, installrequirements-dev.txtand runpytest.suggestion-modeconfiguration 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.