Search in sources :

Example 1 with JsonCreatorGson

use of org.hl7.fhir.r4.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.dstu3.formats.JsonCreatorGson) JsonCreatorCanonical(org.hl7.fhir.dstu3.formats.JsonCreatorCanonical) JsonElement(com.google.gson.JsonElement) SpecialElement(org.hl7.fhir.dstu3.elementmodel.Element.SpecialElement) OutputStreamWriter(java.io.OutputStreamWriter) HashSet(java.util.HashSet)

Example 2 with JsonCreatorGson

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

the class JsonLDParser method compose.

@Override
public void compose(Element e, OutputStream stream, OutputStyle style, String base) throws IOException {
    this.base = base;
    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("@type", "fhir:" + e.getType());
    prop("@context", jsonLDBase + "fhir.jsonld");
    prop("role", "fhir:treeRoot");
    String id = e.getChildValue("id");
    if (base != null && id != null) {
        if (base.endsWith("#"))
            prop("@id", base + e.getType() + "-" + id + ">");
        else
            prop("@id", Utilities.pathURL(base, e.getType(), id));
    }
    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.dstu3.formats.JsonCreatorGson) JsonCreatorCanonical(org.hl7.fhir.dstu3.formats.JsonCreatorCanonical) SpecialElement(org.hl7.fhir.dstu3.elementmodel.Element.SpecialElement) OutputStreamWriter(java.io.OutputStreamWriter) HashSet(java.util.HashSet)

Example 3 with JsonCreatorGson

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

the class JsonLDParser method compose.

@Override
public void compose(Element e, OutputStream stream, OutputStyle style, String base) throws Exception {
    this.base = base;
    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("@context", "http://hl7.org/fhir/jsonld/" + e.getType());
    prop("resourceType", e.getType());
    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.dstu2016may.formats.JsonCreatorGson) JsonCreatorCanonical(org.hl7.fhir.dstu2016may.formats.JsonCreatorCanonical) OutputStreamWriter(java.io.OutputStreamWriter) HashSet(java.util.HashSet)

Example 4 with JsonCreatorGson

use of org.hl7.fhir.r4.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 Exception {
    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());
    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.dstu2016may.formats.JsonCreatorGson) JsonCreatorCanonical(org.hl7.fhir.dstu2016may.formats.JsonCreatorCanonical) SpecialElement(org.hl7.fhir.dstu2016may.metamodel.Element.SpecialElement) JsonElement(com.google.gson.JsonElement) OutputStreamWriter(java.io.OutputStreamWriter) HashSet(java.util.HashSet)

Example 5 with JsonCreatorGson

use of org.hl7.fhir.r4.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.r5.formats.JsonCreatorGson) JsonCreatorCanonical(org.hl7.fhir.r5.formats.JsonCreatorCanonical) JsonElement(com.google.gson.JsonElement) SpecialElement(org.hl7.fhir.r5.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