Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.cyclonedx.Version;
import org.cyclonedx.model.Metadata;
import org.cyclonedx.model.Property;
import org.cyclonedx.model.component.evidence.Occurrence;
import org.cyclonedx.model.metadata.ToolInformation;

import static org.cyclonedx.util.serializer.SerializerUtils.shouldSerializeField;
Expand Down Expand Up @@ -67,7 +66,7 @@ private void createMetadataInfo(
//Tools
parseTools(metadata, jsonGenerator);

if (metadata.getAuthors() != null && shouldSerializeField(metadata, version, "author")) {
if (CollectionUtils.isNotEmpty(metadata.getAuthors()) && shouldSerializeField(metadata, version, "author")) {
if (isXml) {
ToXmlGenerator xmlGenerator = (ToXmlGenerator) jsonGenerator;
writeArrayFieldXML(metadata.getAuthors(), xmlGenerator, "author");
Expand Down Expand Up @@ -132,18 +131,18 @@ else if (version.getVersion() >= Version.VERSION_15.getVersion()) {
jsonGenerator.writeFieldName("tools");
jsonGenerator.writeStartObject();
if (isXml && jsonGenerator instanceof ToXmlGenerator) {
if (choice.getComponents() != null) {
if (CollectionUtils.isNotEmpty(choice.getComponents())) {
writeArrayFieldXML(choice.getComponents(), (ToXmlGenerator) jsonGenerator, "component");
}
if (choice.getServices() != null) {
if (CollectionUtils.isNotEmpty(choice.getServices())) {
writeArrayFieldXML(choice.getServices(), (ToXmlGenerator) jsonGenerator, "service");
}
}
else {
if (choice.getComponents() != null) {
if (CollectionUtils.isNotEmpty(choice.getComponents())) {
writeArrayFieldJSON(jsonGenerator, "components", choice.getComponents());
}
if (choice.getServices() != null) {
if (CollectionUtils.isNotEmpty(choice.getServices())) {
writeArrayFieldJSON(jsonGenerator, "services", choice.getServices());
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/org/cyclonedx/BomJsonGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,18 @@ public void testIssue408Regression_xmlToJson_externalReferenceBom() throws Excep
assertTrue(parser.isValid(loadedFile, version));
}

@Test
public void testServicesMetadata() throws Exception {
Version version = Version.VERSION_16;
Bom bom = createCommonXmlBom("/regression/valid-metadata-tool-no-services.xml");

BomJsonGenerator generator = BomGeneratorFactory.createJson(version, bom);
File loadedFile = writeToFile(generator.toJsonString());

JsonParser parser = new JsonParser();
assertTrue(parser.isValid(loadedFile, version));
}

@Test
public void testIssue562() throws Exception {
Version version = Version.VERSION_16;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<bom serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79" version="1" xmlns="http://cyclonedx.org/schema/bom/1.6">
<metadata>
<tools>
<components>
<component type="application">
<group>Awesome Vendor</group>
<name>Awesome Tool</name>
<version>9.1.2</version>
<hashes>
<hash alg="SHA-1">25ed8e31b995bb927966616df2a42b979a2717f0</hash>
<hash alg="SHA-256">a74f733635a19aefb1f73e5947cef59cd7440c6952ef0f03d09d974274cbd6df</hash>
</hashes>
</component>
</components>
</tools>
</metadata>
<components />
</bom>