diff --git a/src/CycloneDX.Core/Models/Component.cs b/src/CycloneDX.Core/Models/Component.cs index 76d8e9bf..2802ef26 100644 --- a/src/CycloneDX.Core/Models/Component.cs +++ b/src/CycloneDX.Core/Models/Component.cs @@ -187,9 +187,8 @@ public bool NonNullableModified public List ExternalReferences { get; set; } public bool ShouldSerializeExternalReferences() { return ExternalReferences?.Count > 0; } - [XmlArray("components")] - [ProtoMember(21)] - public List Components { get; set; } + //In the xml format, Properties is in front of Components. + //XML serialization uses the member order unless explicitly specified differently. public bool ShouldSerializeComponents() { return Components?.Count > 0; } [XmlArray("properties")] @@ -197,6 +196,10 @@ public bool NonNullableModified [ProtoMember(22)] public List Properties { get; set; } public bool ShouldSerializeProperties() { return Properties?.Count > 0; } + + [XmlArray("components")] + [ProtoMember(21)] + public List Components { get; set; } [XmlElement("evidence")] [ProtoMember(23)] diff --git a/tests/CycloneDX.Core.Tests/Resources/v1.4/valid-properties-components-1.4.xml b/tests/CycloneDX.Core.Tests/Resources/v1.4/valid-properties-components-1.4.xml new file mode 100644 index 00000000..ea0926e4 --- /dev/null +++ b/tests/CycloneDX.Core.Tests/Resources/v1.4/valid-properties-components-1.4.xml @@ -0,0 +1,31 @@ + + + + + Bar + You + Two + Foo + + + + + acme-library + 1.0.0 + + Bar + Foo + + + + acme-sub-library + 1.0.0 + + Bar + Foo + + + + + + diff --git a/tests/CycloneDX.Core.Tests/Xml/v1.4/SerializationTests.cs b/tests/CycloneDX.Core.Tests/Xml/v1.4/SerializationTests.cs index c34d8c69..b245e1fc 100644 --- a/tests/CycloneDX.Core.Tests/Xml/v1.4/SerializationTests.cs +++ b/tests/CycloneDX.Core.Tests/Xml/v1.4/SerializationTests.cs @@ -54,6 +54,7 @@ public class SerializationTests [InlineData("valid-minimal-viable-1.4.xml")] [InlineData("valid-patch-1.4.xml")] [InlineData("valid-properties-1.4.xml")] + [InlineData("valid-properties-components-1.4.xml")] // [InlineData("valid-random-attributes-1.4.xml")] [InlineData("valid-release-notes-1.4.xml")] [InlineData("valid-service-1.4.xml")]