Search in sources :

Example 1 with LocationData

use of org.hl7.fhir.utilities.json.JsonTrackingParser.LocationData in project org.hl7.fhir.core by hapifhir.

the class JsonParser method parse.

@Override
public Element parse(InputStream stream) throws IOException, FHIRFormatError, DefinitionException {
    // if we're parsing at this point, then we're going to use the custom parser
    map = new HashMap<JsonElement, LocationData>();
    String source = TextFile.streamToString(stream);
    if (policy == ValidationPolicy.EVERYTHING) {
        JsonObject obj = null;
        try {
            obj = JsonTrackingParser.parse(source, map);
        } catch (Exception e) {
            logError(-1, -1, "(document)", IssueType.INVALID, "Error parsing JSON: " + e.getMessage(), IssueSeverity.FATAL);
            return null;
        }
        assert (map.containsKey(obj));
        return parse(obj);
    } else {
        JsonObject obj = (JsonObject) new com.google.gson.JsonParser().parse(source);
        // assert (map.containsKey(obj));
        return parse(obj);
    }
}
Also used : LocationData(org.hl7.fhir.utilities.json.JsonTrackingParser.LocationData) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 2 with LocationData

use of org.hl7.fhir.utilities.json.JsonTrackingParser.LocationData in project org.hl7.fhir.core by hapifhir.

the class JsonParser method parse.

@Override
public List<NamedElement> parse(InputStream stream) throws IOException, FHIRException {
    // if we're parsing at this point, then we're going to use the custom parser
    List<NamedElement> res = new ArrayList<>();
    map = new IdentityHashMap<JsonElement, LocationData>();
    String source = TextFile.streamToString(stream);
    if (policy == ValidationPolicy.EVERYTHING) {
        JsonObject obj = null;
        try {
            obj = JsonTrackingParser.parse(source, map, false, allowComments);
        } catch (Exception e) {
            logError(-1, -1, context.formatMessage(I18nConstants.DOCUMENT), IssueType.INVALID, context.formatMessage(I18nConstants.ERROR_PARSING_JSON_, e.getMessage()), IssueSeverity.FATAL);
            return null;
        }
        assert (map.containsKey(obj));
        Element e = parse(obj);
        if (e != null) {
            res.add(new NamedElement(null, e));
        }
    } else {
        // (JsonObject) new com.google.gson.JsonParser().parse(source);
        JsonObject obj = JsonTrackingParser.parse(source, null);
        // assert (map.containsKey(obj));
        Element e = parse(obj);
        if (e != null) {
            res.add(new NamedElement(null, e));
        }
    }
    return res;
}
Also used : LocationData(org.hl7.fhir.utilities.json.JsonTrackingParser.LocationData) JsonElement(com.google.gson.JsonElement) JsonElement(com.google.gson.JsonElement) SpecialElement(org.hl7.fhir.r4b.elementmodel.Element.SpecialElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 3 with LocationData

use of org.hl7.fhir.utilities.json.JsonTrackingParser.LocationData in project org.hl7.fhir.core by hapifhir.

the class JsonParser method parse.

@Override
public List<NamedElement> parse(InputStream stream) throws IOException, FHIRException {
    // if we're parsing at this point, then we're going to use the custom parser
    List<NamedElement> res = new ArrayList<>();
    map = new IdentityHashMap<JsonElement, LocationData>();
    String source = TextFile.streamToString(stream);
    if (policy == ValidationPolicy.EVERYTHING) {
        JsonObject obj = null;
        try {
            obj = JsonTrackingParser.parse(source, map, false, allowComments);
        } catch (Exception e) {
            logError(-1, -1, context.formatMessage(I18nConstants.DOCUMENT), IssueType.INVALID, context.formatMessage(I18nConstants.ERROR_PARSING_JSON_, e.getMessage()), IssueSeverity.FATAL);
            return null;
        }
        assert (map.containsKey(obj));
        Element e = parse(obj);
        if (e != null) {
            res.add(new NamedElement(null, e));
        }
    } else {
        // (JsonObject) new com.google.gson.JsonParser().parse(source);
        JsonObject obj = JsonTrackingParser.parse(source, null);
        // assert (map.containsKey(obj));
        Element e = parse(obj);
        if (e != null) {
            res.add(new NamedElement(null, e));
        }
    }
    return res;
}
Also used : LocationData(org.hl7.fhir.utilities.json.JsonTrackingParser.LocationData) JsonElement(com.google.gson.JsonElement) JsonElement(com.google.gson.JsonElement) SpecialElement(org.hl7.fhir.r5.elementmodel.Element.SpecialElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 4 with LocationData

use of org.hl7.fhir.utilities.json.JsonTrackingParser.LocationData in project org.hl7.fhir.core by hapifhir.

the class JsonParser method parse.

@Override
public Element parse(InputStream stream) throws IOException, FHIRException {
    // if we're parsing at this point, then we're going to use the custom parser
    map = new IdentityHashMap<JsonElement, LocationData>();
    String source = TextFile.streamToString(stream);
    if (policy == ValidationPolicy.EVERYTHING) {
        JsonObject obj = null;
        try {
            obj = JsonTrackingParser.parse(source, map);
        } catch (Exception e) {
            logError(-1, -1, "(document)", IssueType.INVALID, "Error parsing JSON: " + e.getMessage(), IssueSeverity.FATAL);
            return null;
        }
        assert (map.containsKey(obj));
        return parse(obj);
    } else {
        // (JsonObject) new com.google.gson.JsonParser().parse(source);
        JsonObject obj = JsonTrackingParser.parse(source, null);
        // assert (map.containsKey(obj));
        return parse(obj);
    }
}
Also used : LocationData(org.hl7.fhir.utilities.json.JsonTrackingParser.LocationData) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 5 with LocationData

use of org.hl7.fhir.utilities.json.JsonTrackingParser.LocationData in project org.hl7.fhir.core by hapifhir.

the class JsonParser method parse.

@Override
public Element parse(InputStream stream) throws Exception {
    // if we're parsing at this point, then we're going to use the custom parser
    map = new HashMap<JsonElement, LocationData>();
    String source = TextFile.streamToString(stream);
    if (policy == ValidationPolicy.EVERYTHING) {
        JsonObject obj = null;
        try {
            obj = JsonTrackingParser.parse(source, map);
        } catch (Exception e) {
            logError(-1, -1, "(document)", IssueType.INVALID, "Error parsing JSON: " + e.getMessage(), IssueSeverity.FATAL);
            return null;
        }
        assert (map.containsKey(obj));
        return parse(obj);
    } else {
        JsonObject obj = (JsonObject) new com.google.gson.JsonParser().parse(source);
        assert (map.containsKey(obj));
        return parse(obj);
    }
}
Also used : LocationData(org.hl7.fhir.dstu2016may.utils.JsonTrackingParser.LocationData) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException)

Aggregations

JsonElement (com.google.gson.JsonElement)5 JsonObject (com.google.gson.JsonObject)5 IOException (java.io.IOException)5 FHIRException (org.hl7.fhir.exceptions.FHIRException)4 LocationData (org.hl7.fhir.utilities.json.JsonTrackingParser.LocationData)4 ArrayList (java.util.ArrayList)2 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)2 LocationData (org.hl7.fhir.dstu2016may.utils.JsonTrackingParser.LocationData)1 SpecialElement (org.hl7.fhir.r4b.elementmodel.Element.SpecialElement)1 SpecialElement (org.hl7.fhir.r5.elementmodel.Element.SpecialElement)1