Skip to content

Commit

Permalink
Fix metadata>component>properties XML deserialization
Browse files Browse the repository at this point in the history
Fixes #336

Signed-off-by: nscuro <[email protected]>
  • Loading branch information
nscuro committed Oct 17, 2023
1 parent c72eb8b commit 76cb04c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/cyclonedx/model/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import com.github.packageurl.PackageURL;
import org.cyclonedx.util.deserializer.PropertiesDeserializer;

@SuppressWarnings("unused")
@JacksonXmlRootElement(localName = "component")
Expand Down Expand Up @@ -364,6 +365,7 @@ public void setExternalReferences(List<ExternalReference> externalReferences) {

@JacksonXmlElementWrapper(localName = "properties")
@JacksonXmlProperty(localName = "property")
@JsonDeserialize(using = PropertiesDeserializer.class)
public List<Property> getProperties() {
return properties;
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/org/cyclonedx/parsers/JsonParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,11 @@ public void testParsedObjects15Bom_validTools() throws Exception {
assertCommonBomProperties(bom, Version.VERSION_15);
assertMetadata_validTools(bom.getMetadata());
}

@Test
public void testIssue336Regression() throws Exception {
final Bom bom = getJsonBom("regression/issue336.json");
assertEquals("foo", bom.getMetadata().getComponent().getProperties().get(0).getName());
assertEquals("bar", bom.getMetadata().getComponent().getProperties().get(0).getValue());
}
}
7 changes: 7 additions & 0 deletions src/test/java/org/cyclonedx/parsers/XmlParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,11 @@ public void testParsedObjects14Bom_WithVulnsExtension() throws Exception {
assertEquals(1, bom.getVersion());
assertNull(bom.getVulnerabilities());
}

@Test
public void testIssue336Regression() throws Exception {
final Bom bom = getXmlBom("regression/issue336.xml");
assertEquals("foo", bom.getMetadata().getComponent().getProperties().get(0).getName());
assertEquals("bar", bom.getMetadata().getComponent().getProperties().get(0).getValue());
}
}
17 changes: 17 additions & 0 deletions src/test/resources/regression/issue336.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"bomFormat" : "CycloneDX",
"specVersion" : "1.4",
"serialNumber": "urn:uuid:1624fa6f-aebe-4dba-8ead-f2c876c9b832",
"version" : 1,
"metadata": {
"component": {
"name": "acme-app",
"properties": [
{
"name": "foo",
"value": "bar"
}
]
}
}
}
13 changes: 13 additions & 0 deletions src/test/resources/regression/issue336.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<bom xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
serialNumber="urn:uuid:1624fa6f-aebe-4dba-8ead-f2c876c9b832" version="1"
xmlns="http://cyclonedx.org/schema/bom/1.4">
<metadata>
<component type="application">
<name>acme-app</name>
<properties>
<property name="foo">bar</property>
</properties>
</component>
</metadata>
</bom>

0 comments on commit 76cb04c

Please sign in to comment.