Skip to content

Fix serialization of enums with Null values - #453

Open
andreas-hilti wants to merge 1 commit into
CycloneDX:mainfrom
andreas-hilti:fix/enum_null
Open

andreas-hilti wants to merge 1 commit into
CycloneDX:mainfrom
andreas-hilti:fix/enum_null

Conversation

@andreas-hilti

@andreas-hilti andreas-hilti commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #445

The [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] prevents writing the Null value in the Json case, while the ShouldSerialize... member prevents it in the Xml case.

Signed-off-by: andreas hilti <69210561+andreas-hilti@users.noreply.github.com>
@andreas-hilti

andreas-hilti commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor Author

There are a couple of enums that I haven't touched:

  • if they are used in lists: List<CertificationLevel>, List<CryptoFunction>, List<Response>
  • if they are used as nullable: AlgorithmMode?, ExecutionEnvironment?, ImplementationPlatform?, etc. (only partially addressed)

There are also a couple of instances where the enums are required, e.g. DataClassification.Flow; there I prevent writing the "Null" value, but this doesn't guarantee a valid JSON, given that a proper enum value is required.

@andreas-hilti
andreas-hilti marked this pull request as ready for review September 20, 2026 14:54
@andreas-hilti
andreas-hilti requested a review from a team as a code owner September 20, 2026 14:54

This branch has not been deployed

No deployments
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.

Nullability on enums broken

1 participant