简体   繁体   中英

Why HL7 FHIR Json Resources do not have a “root” element

I am implementing a FHIR Server able to receive Resources on both formats (XML/Json). In order to make it simple an consistent, my idea is to internally work just with XML and to translate Json request to XML and vice versa, but although it works with some sample Json documents, it does not work with FHIR Json resources. The main reason is that FHIR Json resources does not have a "root" element, so the XML conversion tool does not create a proper output XML.

A FHIR Json observation resource is like;

{"resourceType": "Observation","id": "example",...}

And with a root element it should be

{Observation:{"id": "example",...}}

I am aware it's not mandatory for a Json document to have a root element, but ¿if most XML<->Json converters work better in that scenario and FHIR accepts both formats, why not defining FHIR Json resources with a root element? specially when it seem that some initial DSTU used that approach.

Thanks

The decision was made to make the JSON the way the JSON people wanted and the XML the way the XML people wanted and to forgo the use of off-the-shelf converters. Using the off-the-shelf converters resulted in syntaxes that one group or the other or both hated. Everyone has to deal with the instances. Custom converters only need to be written once. In any event "why does the specification do things the way it does" is probably not in-scope for Stack Overflow - better to raise it on chat.fhir.org.

You are running against a restriction of XML which JSON does not have. Because you only need the XML for internal use, and you use JSON anywway for interoperability, you might as well wrap your incoming JSON in a root element and remove it when exporting to JSON. I don't think that will cause many lines of code or performance lost.

If you want to change the behaviour of FHIR regarding to this, you better address this somewhere else then Stackoverflow which purpose primarly is to hand over practical solutions.

Best regards

The may challenge for our company regarding this issues is how to manage FHIR JSON requests without changing our back-office technology(Tomcat+Axis2). Before being able to work with official FHIR libraries, I should be able to access JSon request form Axis. If it could be useful to some one working with FHIR and Axis, at the following question I explain who I implemented it Axis2 JSon Support (Jettison) bad xml conversion .

Thks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM