Skip to content

Quote string scalars that resolve to null (#493) - #1126

Open
gaoflow wants to merge 1 commit into
aaubry:masterfrom
gaoflow:quote-null-resolving-strings
Open

Quote string scalars that resolve to null (#493)#1126
gaoflow wants to merge 1 commit into
aaubry:masterfrom
gaoflow:quote-null-resolving-strings

Conversation

@gaoflow

@gaoflow gaoflow commented Jul 28, 2026

Copy link
Copy Markdown

A string equal to a null token (~, null, Null, NULL) is emitted as a plain scalar, so it deserializes back to null even when the target is string — the serializer emits output its own deserializer reads as a different type (#493).

var s = new SerializerBuilder().Build();
var d = new DeserializerBuilder().Build();
d.Deserialize<string>(s.Serialize("null")); // returns null, not "null"

TypeAssigningEventEmitter now quotes a string scalar whose plain form matches the exact set NullNodeDeserializer treats as null, so it round-trips. Only that set is quoted — nUll/nullish stay plain — and actual nulls are unaffected (still emit bare null). It is the same set WithQuotingNecessaryStrings already quotes, applied unconditionally for the null tokens because, unlike bool/number look-alikes, they lose data even for a string target.

Tested: the four tokens round-trip as scalars and dictionary values, look-alikes stay unquoted, and real null still emits bare.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant