From e18433d709a7bb35b8eedc74e4460bed9d5c718a Mon Sep 17 00:00:00 2001 From: James Agnew Date: Wed, 22 Apr 2015 17:45:00 -0400 Subject: [PATCH] Trying to remove empty text node --- .../src/main/java/ca/uhn/fhir/model/primitive/CodeDt.java | 5 +++++ .../src/main/java/ca/uhn/fhir/model/primitive/XhtmlDt.java | 5 +++++ .../test/java/ca/uhn/fhir/parser/JsonParserDstu2Test.java | 6 +++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/CodeDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/CodeDt.java index 089e1117df6..0ef13cc95b4 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/CodeDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/CodeDt.java @@ -44,6 +44,11 @@ public class CodeDt extends BasePrimitive implements ICodedDatatype, Com setValue(theCode); } + @Override + public boolean isEmpty() { + return isBlank(getValueAsString()); + } + @Override public int compareTo(CodeDt theCode) { if (theCode == null) { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/XhtmlDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/XhtmlDt.java index 5ec2f7a4bb1..fd197204099 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/XhtmlDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/XhtmlDt.java @@ -48,6 +48,11 @@ public class XhtmlDt extends BasePrimitive> { // nothing } + @Override + public boolean isEmpty() { + return super.isEmpty() && (getValue() == null || getValue().isEmpty()); + } + /** * Constructor which accepts a string code * 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 654e0c12318..9c1ddd686c3 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 @@ -108,14 +108,18 @@ public class JsonParserDstu2Test { public void testEncodeBundleNewBundleNoText() { ca.uhn.fhir.model.dstu2.resource.Bundle b = new ca.uhn.fhir.model.dstu2.resource.Bundle(); - b.getText().getDiv(); +// b.getText().setDiv("
aaa
"); + b.getText().getStatus().setValueAsString("");; Entry e = b.addEntry(); e.setResource(new Patient()); String val = new FhirContext().newJsonParser().setPrettyPrint(false).encodeResourceToString(b); ourLog.info(val); + assertThat(val, not(containsString("text"))); + val = new FhirContext().newXmlParser().setPrettyPrint(false).encodeResourceToString(b); + ourLog.info(val); assertThat(val, not(containsString("text"))); }