Skip to content

Commit

Permalink
fix: serialization of Rating (#366)
Browse files Browse the repository at this point in the history
Signed-off-by: andreas hilti <[email protected]>
  • Loading branch information
andreas-hilti authored Nov 23, 2024
1 parent 77ecced commit a40ae70
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/CycloneDX.Core/Models/Vulnerabilities/Rating.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using System.Text.Json.Serialization;
using System.Xml.Serialization;
using ProtoBuf;

Expand All @@ -27,17 +28,34 @@ public class Rating
[ProtoMember(1)]
public Source Source { get; set; }

[XmlElement("score")]
[XmlIgnore]
[ProtoMember(2)]
public double Score { get; set; }
public double? Score { get; set; }

[JsonIgnore]
[XmlElement("score")]
public double NonNullableScore
{
get
{
return Score.HasValue ? Score.Value : double.NaN;
}
set
{
Score = value;
}
}
public bool ShouldSerializeNonNullableScore() { return Score.HasValue; }

[XmlElement("severity")]
[ProtoMember(3)]
public Severity Severity { get; set; }
public Severity? Severity { get; set; }

[XmlElement("method")]
[ProtoMember(4)]
public ScoreMethod Method { get; set; }
public bool ShouldSerializeMethod() { return Method != ScoreMethod.Null; }


[XmlElement("vector")]
[ProtoMember(5)]
Expand Down

0 comments on commit a40ae70

Please sign in to comment.