Skip to content

Add DefaultIgnoreCondition support#176

Merged
hadashiA merged 1 commit intomasterfrom
feature/default-ignore-condition
Mar 11, 2026
Merged

Add DefaultIgnoreCondition support#176
hadashiA merged 1 commit intomasterfrom
feature/default-ignore-condition

Conversation

@hadashiA
Copy link
Copy Markdown
Owner

Summary

  • Add YamlIgnoreCondition enum (Never, WhenWritingNull, WhenWritingDefault) and DefaultIgnoreCondition property to YamlSerializerOptions
  • Source generators emit conditional serialization blocks that skip null or default-valued properties based on the configured option
  • Supports both Roslyn 3.8 and 4.1+ source generators

Closes #127

Changes

  • VYaml/Serialization/YamlIgnoreCondition.cs — New enum
  • VYaml/Serialization/YamlSerializerOptions.cs — Added DefaultIgnoreCondition property
  • VYaml.SourceGenerator/Emitter.csEmitIgnoreConditionCheck and GetDefaultValueComparison methods
  • VYaml.SourceGenerator.Roslyn3/VYamlSourceGenerator.cs — Same pattern for Roslyn 3.8
  • VYaml.Tests/ — Tests for Never, WhenWritingNull, WhenWritingDefault modes
  • README.md — Documentation for the new option

Test plan

  • All existing tests pass (36/36 in GeneratedFormatterTest)
  • New tests verify Never mode serializes all properties
  • New tests verify WhenWritingNull omits null reference types and Nullable<T> but keeps default value types
  • New tests verify WhenWritingDefault omits both null and default-valued properties
  • New tests verify non-default values are always serialized regardless of mode

🤖 Generated with Claude Code

@hadashiA hadashiA force-pushed the feature/default-ignore-condition branch from 777d719 to b54ed6e Compare March 10, 2026 05:35
Add YamlIgnoreCondition enum (Never, WhenWritingNull, WhenWritingDefault)
and DefaultIgnoreCondition option to YamlSerializerOptions. Source generators
emit conditional serialization blocks that skip null or default-valued
properties based on the configured ignore condition.

Closes #127

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@hadashiA hadashiA force-pushed the feature/default-ignore-condition branch from b54ed6e to 7c3f683 Compare March 11, 2026 01:02
@hadashiA hadashiA merged commit c436e30 into master Mar 11, 2026
1 check passed
@hadashiA hadashiA deleted the feature/default-ignore-condition branch March 11, 2026 14:17
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.

How to not serialize null values?

1 participant