Don't generate empty JSON element for comment (#4832)
* Don't generate empty JSON element for comment * Fixed
This commit is contained in:
parent
93f93d5e41
commit
d5184a8a57
|
@ -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 (inArray) {
|
||||||
// If this is a repeatable field, the extensions go in an array too
|
// If this is a repeatable field, the extensions go in an array too
|
||||||
beginArray(theEventWriter, '_' + currentChildName);
|
beginArray(theEventWriter, '_' + currentChildName);
|
||||||
|
|
|
@ -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."
|
|
@ -42,6 +42,7 @@ import org.hl7.fhir.r4.model.PrimitiveType;
|
||||||
import org.hl7.fhir.r4.model.Quantity;
|
import org.hl7.fhir.r4.model.Quantity;
|
||||||
import org.hl7.fhir.r4.model.QuestionnaireResponse;
|
import org.hl7.fhir.r4.model.QuestionnaireResponse;
|
||||||
import org.hl7.fhir.r4.model.Reference;
|
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.StringType;
|
||||||
import org.hl7.fhir.r4.model.Type;
|
import org.hl7.fhir.r4.model.Type;
|
||||||
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
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
|
@Test
|
||||||
public void testEncodeExtensionOnBinaryData() {
|
public void testEncodeExtensionOnBinaryData() {
|
||||||
Binary b = new Binary();
|
Binary b = new Binary();
|
||||||
|
|
Loading…
Reference in New Issue