Skip to content

Commit 43098fa

Browse files
author
Greg Gibeling
committed
Switch to XML 1.1 (handles whitespace, writes proper header)
1 parent d25e21d commit 43098fa

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/main/java/org/cyclonedx/generators/xml/AbstractBomXmlGenerator.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.fasterxml.jackson.databind.ObjectMapper;
3737
import com.fasterxml.jackson.databind.module.SimpleModule;
3838
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
39+
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
3940
import com.fasterxml.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter;
4041

4142
public abstract class AbstractBomXmlGenerator extends CycloneDxSchema implements BomXmlGenerator {
@@ -46,6 +47,8 @@ public abstract class AbstractBomXmlGenerator extends CycloneDxSchema implements
4647

4748
public AbstractBomXmlGenerator() {
4849
mapper = new XmlMapper();
50+
// Roche-CSI: Use XML 1.1 to handle extended characters in linux copyright files
51+
((XmlMapper) mapper).configure(ToXmlGenerator.Feature.WRITE_XML_1_1, true);
4952
prettyPrinter = new DefaultXmlPrettyPrinter();
5053
setupObjectMapper(mapper);
5154
}
@@ -56,8 +59,6 @@ public ObjectMapper getMapper() {
5659

5760
Document doc;
5861

59-
protected static final String PROLOG = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
60-
6162
private void setupObjectMapper(final ObjectMapper mapper) {
6263
mapper.setAnnotationIntrospector(
6364
new VersionXmlAnnotationIntrospector(
@@ -116,9 +117,9 @@ protected Document generateDocument(final Bom bom)
116117
String toXML(final Bom bom, final boolean prettyPrint) throws GeneratorException {
117118
try {
118119
if (prettyPrint) {
119-
return PROLOG + System.lineSeparator() + mapper.writer(prettyPrinter).writeValueAsString(bom);
120+
return mapper.writer(prettyPrinter).writeValueAsString(bom);
120121
}
121-
return PROLOG + mapper.writeValueAsString(bom);
122+
return mapper.writeValueAsString(bom);
122123
} catch (JsonProcessingException ex) {
123124
throw new GeneratorException(ex);
124125
}

0 commit comments

Comments
 (0)