Skip to content

Commit

Permalink
Fix tools serialization (for versions < 1.5)
Browse files Browse the repository at this point in the history
Signed-off-by: andreas hilti <andreas.hilti@bluewin.ch>
  • Loading branch information
andreas-hilti committed May 19, 2024
1 parent a27d923 commit c961d2d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/CycloneDX.Core/Json/Converters/ToolChoicesConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@ public override void Write(
Contract.Requires(writer != null);
Contract.Requires(value != null);

if (value.Tools != null)
if (value.Tools != null || value.SpecVersion < SpecificationVersion.v1_5)
{
writer.WriteStartArray();
foreach (var tool in value.Tools)
if (value.Tools != null)
{
JsonSerializer.Serialize(writer, tool, options);
foreach (var tool in value.Tools)
{
JsonSerializer.Serialize(writer, tool, options);
}
}
writer.WriteEndArray();
}
Expand Down
4 changes: 1 addition & 3 deletions tests/CycloneDX.Core.Tests/Json/v1.5/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ public async Task JsonRoundTripAsyncTest(string filename)
[InlineData("valid-service-1.5.json")]
[InlineData("valid-service-empty-objects-1.5.json")]
[InlineData("valid-signatures-1.5.json")]
//TODO - I do not know why this particular one is failing
//Validating it with other tools works, maybe an obscure STJ bug???
//[InlineData("valid-vulnerability-1.5.json")]
[InlineData("valid-vulnerability-1.5.json")]
public void JsonDowngradeTest(string filename)
{
var resourceFilename = Path.Join("Resources", "v1.5", filename);
Expand Down

0 comments on commit c961d2d

Please sign in to comment.