Search in sources :

Example 6 with JsonCreatorGson

use of org.hl7.fhir.dstu2016may.formats.JsonCreatorGson in project org.hl7.fhir.core by hapifhir.

the class JsonParser method compose.

@Override
public void compose(Element e, OutputStream stream, OutputStyle style, String identity) throws FHIRException, IOException {
    OutputStreamWriter osw = new OutputStreamWriter(stream, "UTF-8");
    if (style == OutputStyle.CANONICAL)
        json = new JsonCreatorCanonical(osw);
    else
        json = new JsonCreatorGson(osw);
    json.setIndent(style == OutputStyle.PRETTY ? "  " : "");
    json.beginObject();
    prop("resourceType", e.getType(), null);
    Set<String> done = new HashSet<String>();
    for (Element child : e.getChildren()) {
        compose(e.getName(), e, done, child);
    }
    json.endObject();
    json.finish();
    osw.flush();
}
Also used : JsonCreatorGson(org.hl7.fhir.r4.formats.JsonCreatorGson) JsonCreatorCanonical(org.hl7.fhir.r4.formats.JsonCreatorCanonical) SpecialElement(org.hl7.fhir.r4.elementmodel.Element.SpecialElement) JsonElement(com.google.gson.JsonElement) OutputStreamWriter(java.io.OutputStreamWriter) HashSet(java.util.HashSet)

Example 7 with JsonCreatorGson

use of org.hl7.fhir.dstu2016may.formats.JsonCreatorGson in project org.hl7.fhir.core by hapifhir.

the class JsonParser method compose.

@Override
public void compose(Element e, OutputStream stream, OutputStyle style, String identity) throws FHIRException, IOException {
    OutputStreamWriter osw = new OutputStreamWriter(stream, "UTF-8");
    if (style == OutputStyle.CANONICAL)
        json = new JsonCreatorCanonical(osw);
    else
        json = new JsonCreatorGson(osw);
    json.setIndent(style == OutputStyle.PRETTY ? "  " : "");
    json.beginObject();
    prop("resourceType", e.getType(), null);
    Set<String> done = new HashSet<String>();
    for (Element child : e.getChildren()) {
        compose(e.getName(), e, done, child);
    }
    json.endObject();
    json.finish();
    osw.flush();
}
Also used : JsonCreatorGson(org.hl7.fhir.r4b.formats.JsonCreatorGson) JsonCreatorCanonical(org.hl7.fhir.r4b.formats.JsonCreatorCanonical) JsonElement(com.google.gson.JsonElement) SpecialElement(org.hl7.fhir.r4b.elementmodel.Element.SpecialElement) OutputStreamWriter(java.io.OutputStreamWriter) HashSet(java.util.HashSet)

Aggregations

OutputStreamWriter (java.io.OutputStreamWriter)7 HashSet (java.util.HashSet)7 JsonElement (com.google.gson.JsonElement)5 JsonCreatorCanonical (org.hl7.fhir.dstu2016may.formats.JsonCreatorCanonical)2 JsonCreatorGson (org.hl7.fhir.dstu2016may.formats.JsonCreatorGson)2 SpecialElement (org.hl7.fhir.dstu3.elementmodel.Element.SpecialElement)2 JsonCreatorCanonical (org.hl7.fhir.dstu3.formats.JsonCreatorCanonical)2 JsonCreatorGson (org.hl7.fhir.dstu3.formats.JsonCreatorGson)2 SpecialElement (org.hl7.fhir.dstu2016may.metamodel.Element.SpecialElement)1 SpecialElement (org.hl7.fhir.r4.elementmodel.Element.SpecialElement)1 JsonCreatorCanonical (org.hl7.fhir.r4.formats.JsonCreatorCanonical)1 JsonCreatorGson (org.hl7.fhir.r4.formats.JsonCreatorGson)1 SpecialElement (org.hl7.fhir.r4b.elementmodel.Element.SpecialElement)1 JsonCreatorCanonical (org.hl7.fhir.r4b.formats.JsonCreatorCanonical)1 JsonCreatorGson (org.hl7.fhir.r4b.formats.JsonCreatorGson)1 SpecialElement (org.hl7.fhir.r5.elementmodel.Element.SpecialElement)1 JsonCreatorCanonical (org.hl7.fhir.r5.formats.JsonCreatorCanonical)1 JsonCreatorGson (org.hl7.fhir.r5.formats.JsonCreatorGson)1