Repository navigation
Nullability on enums broken #445
Copy link
Copy link
Open
Description
I tried to create an VEX for a SBOM document. The analysis is In_Triage and therefore no justification is given right now. According to the 1.6 specification, this is fine.
var bom = new Bom
{
SpecVersion = SpecificationVersion.v1_6,
SerialNumber = $"urn:uuid:{Guid.NewGuid()}",
Version = 1,
Vulnerabilities =
[
new()
{
Analysis = new()
{
State = ImpactAnalysisState.In_Triage
}
}
]
};When serializing it to JSON using CycloneDX.Json.Serializer.SerializeAsync I will get:
{
"bomFormat": "CycloneDX",
"specVersion": "1.6",
"serialNumber": "urn:uuid:be8f9457-aaf8-48ae-8f9e-b914f4b7cee1",
"version": 1,
"vulnerabilities": [
{
"analysis": {
"state": "in_triage",
"justification": "null"
}
}
]
}cyclonedx-cli validate --input-file <file> will show:
Validating JSON BOM...
Validation failed:
Some properties did not match the required schema
http://cyclonedx.org/schema/bom-1.6.schema.json#
On instance: :
{
"bomFormat": "CycloneDX",
"specVersion": "1.6",
"serialNumber": "urn:uuid:be8f9457-aaf8-48ae-8f9e-b914f4b7cee1",
"version": 1,
"vulnerabilities": [
{
"analysis": {
"state": "in_triage",
"justification": "null"
}
}
]
}
Some items do not match the required schema; failing indexes: [0]
http://cyclonedx.org/schema/bom-1.6.schema.json#/properties/vulnerabilities
On instance: /vulnerabilities:
[
{
"analysis": {
"state": "in_triage",
"justification": "null"
}
}
]
Some properties did not match the required schema
http://cyclonedx.org/schema/bom-1.6.schema.json#/definitions/vulnerability
On instance: /vulnerabilities/0:
{
"analysis": {
"state": "in_triage",
"justification": "null"
}
}
Some properties did not match the required schema
http://cyclonedx.org/schema/bom-1.6.schema.json#/definitions/vulnerability/properties/analysis
On instance: /vulnerabilities/0/analysis:
{
"state": "in_triage",
"justification": "null"
}
Value should match one of the values specified by the enum
http://cyclonedx.org/schema/bom-1.6.schema.json#/definitions/impactAnalysisJustification
On instance: /vulnerabilities/0/analysis/justification:
null
BOM is not valid.
Manually removing the justification line results in
Validating JSON BOM...
BOM validated successfully.
I therefore assume, that any enum with Null as protobuf helper should not be serialized at all. Can you please fix all types?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
Falco20019 commentedon Sep 15, 2026
As workaround, I now use the following helper class:
And on serialization I use:
andreas-hilti commentedon Sep 16, 2026
I think the fix would be along the line (in Analysis):
public bool ShouldSerializeJustification() { return Justification != ImpactAnalysisJustification.Null; }but this unfortunately this will only help on xml, not on json.
Maybe this would do:
andreas-hilti commentedon Sep 16, 2026
actually probably simpler:
Falco20019 commentedon Sep 17, 2026
Sounds right with the JsonIgnore. Make sure that there are also other enums like that that might be optional and have the Null entry.
andreas-hilti commentedon Sep 20, 2026
See #453