Repository navigation
Leave the writer empty when Newtonsoft TrySerialize fails [patch] - #157
Conversation
Serialize into a local buffer and copy it to the caller's writer only on success. Disposing the JsonTextWriter auto-closes open objects, so a failure partway through left well-formed, truncated JSON behind. Fixes #154 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SETCEsuMvZFcF6qXRguNds
…ffer-output # Conflicts: # Essentials.SerializationProviders.NewtonsoftJson/NewtonsoftJsonSerializationProvider.cs # Essentials.Tests/NewtonsoftJsonSerializationProviderTests.cs
|
SonarCloud Code Analysis failed with 0.0% coverage on new code. The cause is missing coverage data, not untested code: SonarCloud also reports the whole project at 0.0% for this analysis, which means no coverage report reached it. Why: in run 39351070586 the Ubuntu and Windows test jobs ran on 2026-10-20, and the macOS job was re-run on 2026-11-04. The coverage artifacts are uploaded with The three uncovered lines it names are the buffer setup and the final write in Fix: re-run the whole workflow, not just the failed jobs, so the tests and coverage are produced together. I'll start that once the current Analyze & Release job finishes. Generated by Claude Code |
|



Fixes #154
What changed
NewtonsoftJsonSerializationProvider.TrySerializestreamed straight into the caller'sTextWriter. When serialization failed partway (e.g. a self-referencing object), disposing theJsonTextWriterauto-closed the open objects, so the caller was left holding JSON that parses cleanly but is missing data while the method returnedfalse.It now serializes into a local
StringWriterand copies the result to the caller's writer only on success, matching the System.Text.Json provider. The caller's writer is never wrapped, so it also can no longer be closed by the JSON writer.Tests
TrySerialize_CyclicObject_ReturnsFalseAndWritesNothingasserts both thefalsereturn and an empty writer. It fails onmain(writer holds{"Name":"a"}) and passes with the fix.Essentials.Testssuite on net10.0: 1086 passed.Companion issue #155 (depth > 64) is left for its own PR; with this buffering in place, a depth failure there will also leave the writer empty.
Generated by Claude Code