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 @@ -120,6 +120,9 @@ else if (StringUtils.isNotBlank(l.getName())) {
}
else if (lc.getExpression() != null) {
serializeExpressionToXml(lc, toXmlGenerator);
} else {
toXmlGenerator.writeStartArray();
toXmlGenerator.writeEndArray();
}
}

Expand Down Expand Up @@ -155,7 +158,10 @@ private void serializeJson(
else if (licenseChoice.getExpression() != null &&
StringUtils.isNotBlank(licenseChoice.getExpression().getValue())) {
serializeExpressionToJson(licenseChoice, gen);
}
} else {
gen.writeStartArray();
gen.writeEndArray();
}
}

private void serializeExpressionToXml(
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/org/cyclonedx/BomJsonGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.cyclonedx;

import com.fasterxml.jackson.databind.JsonNode;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.cyclonedx.generators.BomGeneratorFactory;
import org.cyclonedx.generators.json.BomJsonGenerator;
Expand Down Expand Up @@ -248,6 +249,29 @@ public void testIssue408Regression_xmlToJson() throws Exception {
assertTrue(parser.isValid(loadedFile, version));
}

@Test
public void testIssue439Regression_jsonEmptyLicense() throws Exception {
Version version = Version.VERSION_16;
Bom bom = new Bom();
bom.addComponent(getComponentWithEmptyLicenseChoice());

BomJsonGenerator generator = BomGeneratorFactory.createJson(version, bom);
String jsonString = generator.toJsonString();

assertFalse(jsonString.isEmpty());
JsonParser parser = new JsonParser();
assertTrue(parser.isValid(jsonString.getBytes(StandardCharsets.UTF_8)));
}

private static Component getComponentWithEmptyLicenseChoice() {
Component component = new Component();
component.setName("xalan");
component.setType(Component.Type.LIBRARY);
component.setLicenses(new LicenseChoice());
component.setPurl("pkg:maven/xalan/[email protected]?type=jar");
return component;
}

@Test
public void schema16_testEvidence() throws Exception {
Version version = Version.VERSION_16;
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/org/cyclonedx/BomXmlGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.cyclonedx;

import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.cyclonedx.exception.ParseException;
import org.cyclonedx.generators.BomGeneratorFactory;
Expand Down Expand Up @@ -375,6 +376,29 @@ public void testIssue408Regression_jsonToXml() throws Exception {
assertTrue(parser.isValid(loadedFile, version));
}

@Test
public void testIssue439Regression_xmlEmptyLicense() throws Exception {
Version version = Version.VERSION_16;
Bom bom = new Bom();
bom.addComponent(getComponentWithEmptyLicenseChoice());

BomXmlGenerator generator = BomGeneratorFactory.createXml(version, bom);
String xmlString = generator.toXmlString();

assertFalse(xmlString.isEmpty());
XmlParser parser = new XmlParser();
assertTrue(parser.isValid(xmlString.getBytes(StandardCharsets.UTF_8)));
}

private static Component getComponentWithEmptyLicenseChoice() {
Component component = new Component();
component.setName("xalan");
component.setType(Component.Type.LIBRARY);
component.setLicenses(new LicenseChoice());
component.setPurl("pkg:maven/xalan/[email protected]?type=jar");
return component;
}

@Test
public void schema16_testEvidence() throws Exception {
Version version = Version.VERSION_16;
Expand Down