Don't generate empty JSON element for comment (#4832)

* Don't generate empty JSON element for comment

* Fixed
This commit is contained in:
James Agnew 2023-05-06 16:05:48 -04:00 committed by GitHub
parent 93f93d5e41
commit d5184a8a57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 1 deletions

View File

@ -553,7 +553,7 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
}
if (!extensions.isEmpty() || !modifierExtensions.isEmpty() || !comments.isEmpty()) {
if (!extensions.isEmpty() || !modifierExtensions.isEmpty() || (!comments.isEmpty() && isSupportsFhirComment())) {
if (inArray) {
// If this is a repeatable field, the extensions go in an array too
beginArray(theEventWriter, '_' + currentChildName);

View File

@ -0,0 +1,6 @@
---
type: fix
issue: 4832
title: "When serializing resources in JSON, if resource came from an XML-parsed resource that
contained comments, the JSON serializer incorrectly created an empty object. This has
been corrected."

View File

@ -42,6 +42,7 @@ import org.hl7.fhir.r4.model.PrimitiveType;
import org.hl7.fhir.r4.model.Quantity;
import org.hl7.fhir.r4.model.QuestionnaireResponse;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.model.StringType;
import org.hl7.fhir.r4.model.Type;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
@ -175,6 +176,36 @@ public class JsonParserR4Test extends BaseTest {
}
@Test
public void testDontEncodeEmptyExtensionList() {
String asXml = """
<Bundle xmlns="http://hl7.org/fhir">
<entry>
<resource>
<Composition>
<section>
<entry>
<!-- Referenz auf PractitionerRole -->
<reference value="PractitionerRole/8f1ba38d-c4c1-4c49-ac2a-7ff0e56bc150" />
</entry>
</section>
</Composition>
</resource>
</entry>
</Bundle>
""";
ourLog.info(asXml);
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, asXml);
String asString = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle);
ourLog.info(asString);
assertThat(asString, not(containsString("{ }")));
}
@Test
public void testEncodeExtensionOnBinaryData() {
Binary b = new Binary();