This commit is contained in:
JasonRoberts-smile 2024-04-11 20:19:56 -04:00 committed by GitHub
parent 6e5c6fa33c
commit e3cc83a694
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 12 deletions

View File

@ -609,12 +609,14 @@ public abstract class BaseParser implements IParser {
private boolean isStripVersionsFromReferences( private boolean isStripVersionsFromReferences(
CompositeChildElement theCompositeChildElement, IBaseResource theResource) { CompositeChildElement theCompositeChildElement, IBaseResource theResource) {
Set<String> autoVersionReferencesAtPathExtensions = if (theResource != null) {
MetaUtil.getAutoVersionReferencesAtPath(theResource.getMeta(), myContext.getResourceType(theResource)); Set<String> autoVersionReferencesAtPathExtensions = MetaUtil.getAutoVersionReferencesAtPath(
theResource.getMeta(), myContext.getResourceType(theResource));
if (!autoVersionReferencesAtPathExtensions.isEmpty() if (!autoVersionReferencesAtPathExtensions.isEmpty()
&& theCompositeChildElement.anyPathMatches(autoVersionReferencesAtPathExtensions)) { && theCompositeChildElement.anyPathMatches(autoVersionReferencesAtPathExtensions)) {
return false; return false;
}
} }
Boolean stripVersionsFromReferences = myStripVersionsFromReferences; Boolean stripVersionsFromReferences = myStripVersionsFromReferences;
@ -622,21 +624,20 @@ public abstract class BaseParser implements IParser {
return stripVersionsFromReferences; return stripVersionsFromReferences;
} }
if (myContext.getParserOptions().isStripVersionsFromReferences() == false) { if (!myContext.getParserOptions().isStripVersionsFromReferences()) {
return false; return false;
} }
Set<String> dontStripVersionsFromReferencesAtPaths = myDontStripVersionsFromReferencesAtPaths; Set<String> dontStripVersionsFromReferencesAtPaths = myDontStripVersionsFromReferencesAtPaths;
if (dontStripVersionsFromReferencesAtPaths != null) { if (dontStripVersionsFromReferencesAtPaths != null
if (dontStripVersionsFromReferencesAtPaths.isEmpty() == false && !dontStripVersionsFromReferencesAtPaths.isEmpty()
&& theCompositeChildElement.anyPathMatches(dontStripVersionsFromReferencesAtPaths)) { && theCompositeChildElement.anyPathMatches(dontStripVersionsFromReferencesAtPaths)) {
return false; return false;
}
} }
dontStripVersionsFromReferencesAtPaths = dontStripVersionsFromReferencesAtPaths =
myContext.getParserOptions().getDontStripVersionsFromReferencesAtPaths(); myContext.getParserOptions().getDontStripVersionsFromReferencesAtPaths();
return dontStripVersionsFromReferencesAtPaths.isEmpty() != false return dontStripVersionsFromReferencesAtPaths.isEmpty()
|| !theCompositeChildElement.anyPathMatches(dontStripVersionsFromReferencesAtPaths); || !theCompositeChildElement.anyPathMatches(dontStripVersionsFromReferencesAtPaths);
} }

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 5842
title: "Fixed a bug where an NPE was being thrown when trying to serialize a FHIR fragment (e.g., backboneElement
, compound datatype) to a string representation if the fragment contains a `Reference`."

View File

@ -1168,6 +1168,18 @@ public class JsonParserR4Test extends BaseTest {
assertEquals(expected, actual); assertEquals(expected, actual);
} }
@Test
public void testEncodeToString_CompoundTypeWithReference() {
Identifier identifier = new Identifier();
identifier.setSystem("http://system.org");
identifier.setValue("123");
Reference reference = new Reference("Organization/1");
identifier.setAssigner(reference);
String expected = "{\"system\":\"http://system.org\",\"value\":\"123\",\"assigner\":{\"reference\":\"Organization/1\"}}";
String actual = ourCtx.newJsonParser().encodeToString(identifier);
assertEquals(expected, actual);
}
@Test @Test
public void testEncodeToString_Resource() { public void testEncodeToString_Resource() {
Patient p = new Patient(); Patient p = new Patient();