diff --git a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/resource/BaseResource.java b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/resource/BaseResource.java index b485f292099..9c257ddc131 100644 --- a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/resource/BaseResource.java +++ b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/resource/BaseResource.java @@ -82,7 +82,7 @@ public abstract class BaseResource extends BaseElement implements IResource { private IdDt myId; - @Child(name = "language", order = 0, min = 0, max = Child.MAX_UNLIMITED) + @Child(name = "language", order = 0, min = 0, max = 1) private CodeDt myLanguage; private ResourceMetadataMap myResourceMetadata; 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 12dec931ea4..a3dd22d3f33 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 @@ -64,6 +64,7 @@ import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum; import ca.uhn.fhir.model.dstu2.valueset.MaritalStatusCodesEnum; import ca.uhn.fhir.model.dstu2.valueset.ObservationStatusEnum; import ca.uhn.fhir.model.dstu2.valueset.UnknownContentCodeEnum; +import ca.uhn.fhir.model.primitive.CodeDt; import ca.uhn.fhir.model.primitive.DateDt; import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.IdDt; @@ -496,7 +497,24 @@ public class JsonParserDstu2Test { assertThat(encoded, not(containsString("tag"))); } - + + @Test + public void testEncodeAndParseLanguage() { + Patient p = new Patient(); + p.setLanguage(new CodeDt("en_CA")); + + String encoded = ourCtx.newJsonParser().encodeResourceToString(p); + ourLog.info(encoded); + + assertEquals("{\"resourceType\":\"Patient\",\"language\":\"en_CA\"}", encoded); + + p = (Patient) ourCtx.newJsonParser().parseResource(encoded); + assertEquals("en_CA", p.getLanguage().getValue()); + + p = (Patient) ourCtx.newJsonParser().parseResource("{\"resourceType\":\"Patient\",\"language\":[\"en_CA\"]}"); + assertEquals("en_CA", p.getLanguage().getValue()); + } + /** * #158 */ diff --git a/src/changes/changes.xml b/src/changes/changes.xml index cdb86c464a7..2e443608f13 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -213,6 +213,10 @@ An example has been added which shows how to do this here]]> + + JSON parser was incorrectly encoding resource language attribute in JSON as an + array instead of a string. Thanks to David Hay for reporting! +