Skip to content

fix(toon): treat empty key-value as nil for nilable scalar fields#242

Open
tleish wants to merge 1 commit intovicentereig:mainfrom
tleish:fix/toon-empty-key-value-nilable-scalar-241
Open

fix(toon): treat empty key-value as nil for nilable scalar fields#242
tleish wants to merge 1 commit intovicentereig:mainfrom
tleish:fix/toon-empty-key-value-nilable-scalar-241

Conversation

@tleish
Copy link
Contributor

@tleish tleish commented Mar 9, 2026

Summary

Failing tests that illustrate #241 — when the TOON codec decodes key: with no value, it returns {} per TOON spec §8. This causes TypeError: Cannot coerce Hash to String when the field is a nilable scalar like T.nilable(String).

Tests added

  • treats empty key-value as nil for nilable string fieldsnickname: with no value should be nil, not {}
  • preserves empty key-value as empty hash for nilable hash fieldsmetadata: with no value should remain {} since it's a valid empty hash
  • treats empty key-value as nil for nilable struct with required fieldssource: with no value should be nil when the struct has required fields

Ref #241

…vicentereig#241

When the TOON codec decodes `key:` with no value, it returns `{}`
per TOON spec §8. The Reconstructor now skips `{}` for types where
it is not valid and the type is nilable, allowing Sorbet to apply
the field's default value.
@tleish
Copy link
Contributor Author

tleish commented Mar 9, 2026

Added RED/failing tests for now

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