[Internal] DTS: Removes dead code and refactors to manual JSON deserialization#5896
Conversation
…alization - Remove unused copy constructor, ErrorMessage property, ITrace plumbing, and per-operation ActivityId/Trace dead stores from response classes - Replace System.Text.Json attribute-based deserialization with manual case-insensitive JsonElement.TryGetProperty parsing - Make SessionToken, PartitionKeyRangeId, and SubStatusCode internal (were public only to satisfy STJ reflection requirements) - Remove public SubStatusCodeValue bridge property (no longer needed) - Add null-safety guards for string fields in JSON deserialization
kushagraThapar
left a comment
There was a problem hiding this comment.
Thanks for the cleanup, @Meghana-Palaparthi — the manual JSON deserializer is the right shape and aligns nicely with what TransactionalBatchOperationResult, Java's BatchResponseParser, and Python's batch-response paths already do (no STJ attributes, direct property walks). The public→internal demotions for SessionToken / PartitionKeyRangeId / SubStatusCode / ActivityId / Trace also bring DTS in line with TransactionalBatchOperationResult.cs:94,99,104, which I think is the right consolidation.
Approving since this is [Internal] and there are no shipped customers yet. I've left a few inline observations on correctness fidelity vs the old JsonSerializer.Deserialize<T> path that would be worth picking up in a follow-up PR — especially the InvalidOperationException leak from EnumerateObject() and the silent-default behavior on numeric type mismatches. These are subtle behavior changes customers won't see today, but the DTS team is likely to hit them during internal testing.
None of the inline items block this PR — they're all opportunities for a small fast-follow.
kushagraThapar
left a comment
There was a problem hiding this comment.
LGTM, thanks @Meghana-Palaparthi
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
📝 Changelog reminder (non-blocking)This PR touches shipped source but does not appear to update the Touched (and missing entry for):
How to decideUse the rubric in
This check is non-blocking — merge is not gated on it. The |
…ibutes, consolidate tests - All property name lookups (including resourceBody) now use case-insensitive TryGetProperty; removed unused TryGetPropertyOrdinal method - Top-level response properties (isRetriable, diagnosticString, operationResponses) switched from ordinal to case-insensitive lookup - Removed [JsonIgnore], [JsonConstructor] attributes and System.Text.Json.Serialization using (dead code since manual FromJson parsing) - Changed parameterless constructor from public back to internal - Consolidated repetitive tests into DataTestMethods (NumericTypeMismatch + NonObjectElement, Indexer bounds, IdempotencyToken fallback) - Removed redundant tests (Dispose_ReleasesResultResourceStreams, FollowedByDirectStreamRead) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
kushagraThapar
left a comment
There was a problem hiding this comment.
LGTM, thanks @Meghana-Palaparthi
Pull Request Template
Description
This pull request refactors the distributed transaction response and operation result handling in the Cosmos DB SDK. The main focus is on removing dependencies on
System.Text.Json.Serializationattributes and reflection-based deserialization, instead implementing explicit JSON parsing logic. Additionally, error message and tracing fields are removed from the public API surface and internal data flow, simplifying the object model.Serialization and Deserialization Refactoring
System.Text.Json.Serializationattributes (such as[JsonInclude],[JsonPropertyName],[JsonIgnore], and[JsonConstructor]) fromDistributedTransactionOperationResultand replaced reflection-based deserialization with a manual, case-insensitive property lookup and assignment in the newFromJsonmethod. (DistributedTransactionOperationResult.cs)TryGetPropertyfor case-insensitive property lookup when parsing JSON elements. (DistributedTransactionOperationResult.cs)DistributedTransactionResponseto use the new explicit parsing methods instead of relying onSystem.Text.Jsonattributes. (DistributedTransactionResponse.cs) [1] [2]Error Message and Tracing Cleanup
ErrorMessageproperty and associated logic fromDistributedTransactionResponseand related constructors, as well as the corresponding test assertions. (DistributedTransactionResponse.cs,DistributedTransactionResponseTests.cs) [1] [2] [3] [4] [5]TraceandActivityIdfields from bothDistributedTransactionResponseandDistributedTransactionOperationResult, and eliminated their propagation through constructors and methods. (DistributedTransactionResponse.cs,DistributedTransactionOperationResult.cs) [1] [2] [3] [4] [5]Public API Simplification
DistributedTransactionOperationResult(such asSessionToken,PartitionKeyRangeId, andSubStatusCode) from public to internal, further restricting their visibility and clarifying the public API. (DistributedTransactionOperationResult.cs)Test Adjustments
SubStatusCodeValue). (DistributedTransactionResponseTests.cs) [1] [2]These changes collectively improve maintainability, reduce reliance on reflection and serialization attributes, and clarify the SDK's public and internal APIs.
Type of change
Please delete options that are not relevant.
Closing issues
To automatically close an issue: closes #IssueNumber
Changelog
### Unreleasedinchangelog.mdfor the user-facing impact of this change.
documentation-only, test-only, CI / build-only, or a pure internal refactor
with no observable customer impact.
If the second box is checked, briefly justify here: