diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java index 2468f079646..efd3eeff857 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java @@ -45,6 +45,7 @@ import javax.xml.stream.events.Namespace; import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; +import ca.uhn.fhir.model.api.BaseBundle; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBase; @@ -309,12 +310,7 @@ public class XmlParser extends BaseParser implements IParser { writeOptionalTagWithTextNode(eventWriter, "updated", theBundle.getUpdated()); - if (StringUtils.isNotBlank(theBundle.getAuthorName().getValue())) { - eventWriter.writeStartElement("author"); - writeTagWithTextNode(eventWriter, "name", theBundle.getAuthorName()); - writeOptionalTagWithTextNode(eventWriter, "uri", theBundle.getAuthorUri()); - eventWriter.writeEndElement(); - } + writeAuthor(eventWriter, theBundle); writeCategories(eventWriter, theBundle.getCategories()); @@ -366,6 +362,8 @@ public class XmlParser extends BaseParser implements IParser { writeOptionalTagWithTextNode(eventWriter, "updated", nextEntry.getUpdated()); writeOptionalTagWithTextNode(eventWriter, "published", nextEntry.getPublished()); + writeAuthor(eventWriter, nextEntry); + writeCategories(eventWriter, nextEntry.getCategories()); if (!nextEntry.getLinkSelf().isEmpty()) { @@ -1070,6 +1068,15 @@ public class XmlParser extends BaseParser implements IParser { return retVal; } + private void writeAuthor(XMLStreamWriter theEventWriter, BaseBundle theBundle) throws XMLStreamException { + if (StringUtils.isNotBlank(theBundle.getAuthorName().getValue())) { + theEventWriter.writeStartElement("author"); + writeTagWithTextNode(theEventWriter, "name", theBundle.getAuthorName()); + writeOptionalTagWithTextNode(theEventWriter, "uri", theBundle.getAuthorUri()); + theEventWriter.writeEndElement(); + } + } + private void writeAtomLink(XMLStreamWriter theEventWriter, String theRel, StringDt theStringDt) throws XMLStreamException { if (StringUtils.isNotBlank(theStringDt.getValue())) { theEventWriter.writeStartElement("link"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java index 1486f293126..edd620a8cf3 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java @@ -428,6 +428,25 @@ public class XmlParserTest { } + @Test + public void testEncodeBundleEntryAuthor() { + + Bundle b = new Bundle(); + BundleEntry e = b.addEntry(); + e.getAuthorName().setValue("The Author"); + e.setResource(new Patient()); + + String val = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b); + ourLog.info(val); + + assertThat(val, StringContains.containsString("The Author")); + + b = ourCtx.newXmlParser().parseBundle(val); + assertEquals(1, b.getEntries().size()); + assertEquals("The Author", b.getEntries().get(0).getAuthorName().getValue()); + + } + @Test public void testEncodeBundleCategory() {