Repository navigation
Leave records whose only ToString is compiler-generated to System.Text.Json [patch] - #136
Merged
Merged
Conversation
…t.Json [patch]
OverridesToString counted the ToString the compiler synthesizes for every
record and record struct as a user override, so a value object such as
`record Email(string Value)` with a static Create was claimed by the
factory and written in its debug form "Email { Value = a@b.c }". Reading
that back passed the whole debug string to Create, nesting it on every
save/load cycle, and JSON written before the factory was registered could
no longer be read.
A ToString marked [CompilerGenerated] no longer counts as an override.
Records that declare their own ToString, or inherit a sealed one, are
still claimed, since the compiler then synthesizes nothing.
Fixes #135
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW3mca4cGmHKaFu4Yui
# Conflicts: # README.md
|
This was referenced Nov 11, 2026
This was referenced Nov 16, 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 #135
Problem
OverridesToStringcounted theToString()the compiler synthesizes for everyrecordandrecord structas a user override. So a value object likerecord Email(string Value)with a staticCreatewas claimed by the factory and written as"Email { Value = a@b.c }". Reading that back passed the whole debug string toCreate, which nested it again on every save/load cycle. JSON written before the factory was registered ({"Value":"a@b.c"}) could no longer be read.Change
ToString()marked[CompilerGenerated]no longer counts as an override, so those records go back to System.Text.Json's default object serialization.ToString(), or inherit asealedone (theSemanticString<T>shape), are still claimed. In both cases the compiler synthesizes nothing.ToStringoverrides now mentions records.I didn't walk up to the base type's
ToStringas the issue suggested. A record deriving from a base with a non-sealedToStringgets its own synthesizedToString, and at runtime that override prints the debug form. Walking up would claim the type and still writeDerived { ... }.Tests
ToStringOverrideTestsgains:Createrecord structwithParseToStringToStringThe four tests for the compiler-generated cases fail on
mainand pass with the fix. All 152 tests pass, includingNetStandardAssetTestsand theSemanticString<T>tests.Generated by Claude Code