Stream: implementers
Topic: Bundle schema
Tim Coates (Feb 20 2017 at 15:18):
Hi just spotted the mismatch between how a DSTU2 Bundle is built in JSON vs XML. It would seem that the JSON structure doesn't match the UML or the Structure views? Is this intentional, is there a reason for it? The key difference I'm struggling with is the difference between /Bundle/entry/resource[array] and /Bundle/entry[array]/resource
Grahame Grieve (Feb 20 2017 at 17:17):
The difference is the presence in XML of the wrapper element- json follows the logical model more closely
Lloyd McKenzie (Feb 20 2017 at 18:59):
@Tim Coates Can you submit a change proposal?
Grahame Grieve (Feb 20 2017 at 21:18):
What change?
Lloyd McKenzie (Feb 20 2017 at 23:21):
Sorry, wrong thread.
Tim Coates (Feb 22 2017 at 09:08):
Really? (Looking at DSTU) The tree view shows in the entry element it has 0..1 resource child elements. XML does this, but JSON has one entry, with an array of resources (and hence IMHO does not follow the logical model). Either serialisation format could implement either approach, the fact they're different is what trips me up.
Grahame Grieve (Feb 24 2017 at 19:02):
DomainResource, contained is 0..* resource.
So the json representation is an array of resources.
The xml representation is a repeating element 'contained' that each contains a resource
Grahame Grieve (Feb 24 2017 at 19:02):
the special thing is that XML has an extra element in there for the resource root element that json doesn't. It's xml that varies from repreesneting the logical model directly
Tim Coates (Feb 26 2017 at 10:34):
It's the json entry having multiple resources that caused us a problem. According to https://www.hl7.org/fhir/bundle.html Bundle.entry has 0..1 resources, but in the json serialisation that's not the case. We can work with it, just seems an unnecessary variation.
Grahame Grieve (Feb 26 2017 at 10:38):
where in the json serialisation is that not the case?
Tim Coates (Feb 27 2017 at 10:57):
So when I retrieve (using HAPI client code) a Bundle from our server in XML, and serialise it as XML, I see a sequence of 'entry' objects each holding one 'resource':
<type value="searchset"/>
<total value="4"/>
<entry>
<resource>
<DocumentReference xmlns="http://hl7.org/fhir">
</resource>
</entry>
<entry>
<resource>
<DocumentReference xmlns="http://hl7.org/fhir">
</resource>
</entry>
<entry>
<resource>
<DocumentReference xmlns="http://hl7.org/fhir">
</resource>
</entry>
<entry>
<resource>
<DocumentReference xmlns="http://hl7.org/fhir">
</resource>
</entry>
But when I serialise that same Bundle to JSON it's one 'entry' which has an array of 'resource' elements:
"type": "searchset",
"total": 4,
"entry": [
{
"resource": {
"resourceType": "DocumentReference",
}
},
{
"resource": {
"resourceType": "DocumentReference",
}
},
{
"resource": {
"resourceType": "DocumentReference",
}
},
{
"resource": {
"resourceType": "DocumentReference",
}
}
]
Pascal Pfiffner (Feb 27 2017 at 11:01):
Yes, that's expected and that's usually how array serialization between XML and JSON differs. Each <entry>...</entry>
is one entry in XML, and each {...}
in "entry" is one entry in JSON. Does this make sense?
Tim Coates (Feb 27 2017 at 11:06):
I can follow how it 'is' implemented and we can work around it, but I don't understand 'why' they differ. I'd have thought either serialisation could easily implement either approach, and ideally they'd take the same approach.
Grahame Grieve (Feb 27 2017 at 11:07):
no. JSON forces there to be a difference from XML. you cannot repeat named properties in json, and you cannot do json arrays in xml
Last updated: Apr 12 2022 at 19:14 UTC