hapi-fhir icon indicating copy to clipboard operation
hapi-fhir copied to clipboard

Bundle Json with "urn" parses JSON but then deletes if upon encode.

Open bionicode opened this issue 2 years ago • 2 comments

I am having difficulty with urn's in a Bundle, and I lose the resourceId if I parse and then encode. I see in JsonParser.java where the code nulls the resource id if it starts with "urn".

Why is the code explicitly nulling the resource id if it starts with "urn" ?

In the following example, a parse followed by an encode loses "id": "8001b082-0493-31de-3e6c-4e5d41d6ac87"

Given the following as a source json, the parse works, and inspecting the Bundle object, all is well.

{ "resourceType": "Bundle", "type": "transaction", "entry": [ { "fullUrl": "urn:uuid:8001b082-0493-31de-3e6c-4e5d41d6ac87", "resource": { "resourceType": "Patient", "id": "8001b082-0493-31de-3e6c-4e5d41d6ac87", "meta": { ...

But then, when I encode, I get the following with the id missing

{ "resourceType": "Bundle", "type": "transaction", "entry": [ { "fullUrl": "urn:uuid:8001b082-0493-31de-3e6c-4e5d41d6ac87", "resource": { "resourceType": "Patient", "meta": {

Environment (please complete the following information):

  • HAPI FHIR Version = 5.7
  • OS: [e.g. iOS] = Apple Monterey on M1 Max chip

bionicode avatar Mar 30 '22 15:03 bionicode

I think what you are experiencing is a combination of two things. First, during parsing, the id is replaced with the fullUrl of the bundle entry. Then in json encoding, it is being dropped explicitly here as you mentioned. If you want to preserve the original id, you can setOverrideResourceIdWithBundleEntryFullUrl to false.

bashir2 avatar Sep 14 '22 16:09 bashir2