Stream: implementers
Topic: Java: Base to JSON
Patrick Werner (Jun 06 2021 at 15:13):
I'm curently trying to get a JSON/XML, or at least String representation of Base Instances.
Patrick Werner (Jun 06 2021 at 15:15):
I couldn't find an encoder for encoding Base Instances, or Elements. Did i miss something?
If there is no code existent i would use: listChildrenByName in Base, check if these are primitives -> get primitive Value, if non-primitive, iterate deeper.
Patrick Werner (Jun 06 2021 at 15:16):
This could get me some kind of String representation, but i was wondering if i just missed existing code which produces nice XML or JSON fragments from Base/Element
Patrick Werner (Jun 06 2021 at 15:17):
I'm getting the Base Instances while evaluating FHIRPaths, also tried: evaluateToString in the FhirPathEngine, wich isn't that helpful at the moment.
Grahame Grieve (Jun 07 2021 at 00:30):
is this a #hapi question? I'm not sure what to make of it in general; there is no representation for Base since it's abstract. Or are you looking for org.hl7.fhir.r5.elementmodel ?
Patrick Werner (Jun 07 2021 at 06:40):
When evaluation FHIR Paths you end up with a List<Base>. I wanted to encode these Base Objects/Elements to Json, but failed to do so.
I then looked at the hapi and Java Json Parser classes, but couldn't find methods to serialize a Base or Element Objekt.
Patrick Werner (Jun 07 2021 at 06:42):
The code for creating Json/XML representations for Fhir elements seems to be only inluded online in the resource creating parts of the parser. I had the hope for a method like this: JSONObject getJsonFromBase(Base base)
Grahame Grieve (Jun 07 2021 at 06:47):
hmm yes. that's complicated since you might want either composer, depending on the actual specialization in the list of base objects. I can't get to it today, but I could add a method for that. Not exactly sure where, but it's certainly possible. Just a bit of rooting around
Patrick Werner (Jun 07 2021 at 06:49):
Sounds great. I think this could also lead to some structural refactoring of the JsonEncoder. Extracting the String creator parts for elements into their own methods.
Grahame Grieve (Jun 07 2021 at 06:50):
really? which methods are you talking about?
Patrick Werner (Jun 07 2021 at 07:14):
it was too late yesterday.. i only saw the handling for meta and id in the hapi parser and assumed that every dataType is handled by its own code. Which was wrong.
Patrick Werner (Jul 24 2021 at 17:25):
should i add an issue for this one on fhir.core?
Last updated: Apr 12 2022 at 19:14 UTC