Skip to content

Commit

Permalink
If autoEmpty, this should also affect null elements
Browse files Browse the repository at this point in the history
  • Loading branch information
javaduke committed Nov 14, 2024
1 parent e6f4801 commit c915c49
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ class BadgerFishWriter(val params: EffectiveParams) {
}
}

if (children.isEmpty && params.autoEmpty) {
val isNullElement = element.equals("nullElement") || element.endsWith(":nullElement")

if ((children.isEmpty || isNullElement) && params.autoEmpty) {
sb append "/>"
} else {
// children, so use long form: <xyz ...>...</xyz>
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/datasonnet/XMLWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,17 @@ void testEmptyElements() throws Exception {

String mappedXml = mapper.transform(new DefaultDocument<>(jsonData, MediaTypes.APPLICATION_JSON), Collections.emptyMap(), MediaTypes.APPLICATION_XML).getContent();

assertThat(mappedXml, CompareMatcher.isSimilarTo(expectedXml).ignoreWhitespace());
//assertThat(mappedXml, CompareMatcher.isSimilarTo(expectedXml).ignoreWhitespace());
assertThat(mappedXml, CompareMatcher.isIdenticalTo(expectedXml).ignoreWhitespace());

expectedXml = TestResourceReader.readFileAsString("xmlEmptyElementsNoNull.xml");
datasonnet = TestResourceReader.readFileAsString("xmlEmptyElementsNoNull.ds");

mapper = new Mapper(datasonnet);


mappedXml = mapper.transform(new DefaultDocument<>(jsonData, MediaTypes.APPLICATION_JSON), Collections.emptyMap(), MediaTypes.APPLICATION_XML).getContent();

assertThat(mappedXml, CompareMatcher.isSimilarTo(expectedXml).ignoreWhitespace());
assertThat(mappedXml, CompareMatcher.isIdenticalTo(expectedXml).ignoreWhitespace());
}

@Test
Expand Down

0 comments on commit c915c49

Please sign in to comment.