[(master)] Added check for sub-extensions.

This commit is contained in:
Simon Marco Janic 2017-11-06 11:06:42 +01:00
parent b4032f4e8c
commit 1c1098a2b7
2 changed files with 14 additions and 0 deletions

View File

@ -734,6 +734,9 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
beginArray(theEventWriter, arrayName);
for (Map.Entry<ResourceMetadataKeyEnum<?>, Object> key : extensions) {
ExtensionDt extension = (ExtensionDt) key.getValue();
if (!extension.getAllUndeclaredExtensions().isEmpty()) {
throw new IllegalArgumentException("Sub-extensions on metadata isn't supported");
}
theEventWriter.beginObject();
writeOptionalTagWithTextNode(theEventWriter, "url", extension.getUrl());
String extensionDatatype = myContext.getRuntimeChildUndeclaredExtensionDefinition().getChildNameByDatatype(extension.getValue().getClass());

View File

@ -1745,6 +1745,17 @@ public class JsonParserDstu2Test {
// @formatter:on
}
@Test(expected = IllegalArgumentException.class)
public void testCannotEncodeSubextensionsOnMeta() {
ProcedureRequest procedureRequest = new ProcedureRequest();
procedureRequest.setStatus(ProcedureRequestStatusEnum.ACCEPTED);
ExtensionDt parent = new ExtensionDt(false, "#parent");
parent.addUndeclaredExtension(new ExtensionDt(false, "#child", new DurationDt().setValue(123)));
procedureRequest.getResourceMetadata().put(new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey(parent.getUrl()), parent);
String json = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(procedureRequest);
}
private void addExtensionResourceMetadataKeyToResource(BaseResource resource, boolean isModifier, String url, String value) {
ExtensionDt extensionDt = new ExtensionDt(isModifier, url, new StringDt(value));
resource.getResourceMetadata()