diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2Test.java index 0dc6bdfffab..567b6c4fc89 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2Test.java @@ -1811,6 +1811,34 @@ public class JsonParserDstu2Test { TestUtil.clearAllStaticFieldsForUnitTest(); } + /** + * See #537 + */ + @Test + public void testEncodeNestedContained() { + + Organization org04 = new Organization(); + org04.setName("LEVEL04"); + + Organization org03 = new Organization(); + org03.setName("LEVEL03"); + org03.getPartOf().setResource(org04); + + Organization org02 = new Organization(); + org02.setName("LEVEL02"); + org02.getPartOf().setResource(org03); + + Organization org01 = new Organization(); + org01.setName("LEVEL01"); + org01.getPartOf().setResource(org02); + + String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(org01); + ourLog.info(encoded); + + assertThat(encoded, stringContainsInOrder("LEVEL02","LEVEL03","LEVEL04","LEVEL01" )); + } + + /** * See #505 */