FHIR Chat · JSON serializer · hapi

Stream: hapi

Topic: JSON serializer


view this post on Zulip Ryan Bobko (Apr 17 2017 at 18:35):

Hi All...I'm new to FHIR and found the HAPI APIs make it pretty easy to create AuditEvents. However, I can't figure out how to serialize these to a stream. In particular, I'm looking for something that takes my AuditEvent and writes/creates a JSON object to my log file. Advice/Hints/Directions greatly appreciated.

view this post on Zulip Mustafa Yuksel (Apr 18 2017 at 07:49):

Hi Ryan. There are several examples in HAPI documentation. For instance: http://hapifhir.io/doc_dstu2.html:

// Create a context for DSTU3
FhirContext ctx = FhirContext.forDstu3();

// Working with RI structures is similar to how it works with the HAPI structures
org.hl7.fhir.dstu3.model.Patient patient = new org.hl7.fhir.dstu3.model.Patient();
patient.addName().addGiven("John").setFamily("Smith");
patient.getBirthDateElement().setValueAsString("1998-02-22");

// Parsing and encoding works the same way too
String encoded = ctx.newJsonParser().encodeResourceToString(patient);

Last updated: Apr 12 2022 at 19:14 UTC