Skip to content

fix: enhance custom converter handling to skip empty checks and improve serialization logic#8

Merged
glucaci merged 1 commit into
mainfrom
fix-custom-generator
Jan 9, 2026
Merged

fix: enhance custom converter handling to skip empty checks and improve serialization logic#8
glucaci merged 1 commit into
mainfrom
fix-custom-generator

Conversation

@glucaci

@glucaci glucaci commented Jan 9, 2026

Copy link
Copy Markdown
Member

This pull request improves the handling of custom converters in the YAML serialization framework, particularly around delegation to generated code and the interaction with the IgnoreEmptyObjects option. It strengthens the contract for generated read/write delegates, ensures correct serialization behavior for custom converters with nested nullable objects, and adds comprehensive tests for these scenarios.

Custom Converter Contract Improvements

  • The GeneratedRead and GeneratedWrite properties in YamlConverter<T> are now non-nullable and throw clear exceptions if accessed before initialization, making the contract for custom converters more robust and developer-friendly. [1] [2] [3]
  • Updated usage of GeneratedRead and GeneratedWrite in custom converters and documentation to remove null-forgiving operators, reflecting the new non-nullable contract. [1] [2]

Source Generator Logic

  • The source generator now skips generating IsEmpty checks for types with custom converters, ensuring that custom converters have full control over serialization logic and are not affected by empty-object optimizations.

Testing and Validation

  • Added extensive tests to verify that custom converters with nested nullable objects behave correctly when IgnoreEmptyObjects is enabled: properties with custom converters are always written (unless null), and round-tripping preserves data as expected. [1] [2]
  • Introduced new model and context classes in the test suite to support these scenarios and clarify test intent.

@glucaci glucaci merged commit 93a4079 into main Jan 9, 2026
1 check passed
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