001package ca.uhn.fhir.parser; 002 003/* 004 * #%L 005 * HAPI FHIR - Core Library 006 * %% 007 * Copyright (C) 2014 - 2021 Smile CDR, Inc. 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import java.io.IOException; 024 025import org.hl7.fhir.instance.model.api.IAnyResource; 026import org.hl7.fhir.instance.model.api.IBaseResource; 027 028import ca.uhn.fhir.model.api.IResource; 029import ca.uhn.fhir.parser.json.JsonLikeStructure; 030import ca.uhn.fhir.parser.json.JsonLikeWriter; 031 032/** 033 * An extension to the parser interface that is implemented by parsers that understand a generalized form of 034 * JSON data. This generalized form uses Map-like, List-like, and scalar elements to construct resources. 035 * <p> 036 * Thread safety: <b>Parsers are not guaranteed to be thread safe</b>. Create a new parser instance for every thread or 037 * every message being parsed/encoded. 038 * </p> 039 */ 040public interface IJsonLikeParser extends IParser { 041 042 void encodeResourceToJsonLikeWriter(IBaseResource theResource, JsonLikeWriter theJsonLikeWriter) throws IOException, DataFormatException; 043 044 /** 045 * Parses a resource from a JSON-like data structure 046 * 047 * @param theResourceType 048 * The resource type to use. This can be used to explicitly specify a class which extends a built-in type 049 * (e.g. a custom type extending the default Patient class) 050 * @param theJsonLikeStructure 051 * The JSON-like structure to parse 052 * @return A parsed resource 053 * @throws DataFormatException 054 * If the resource can not be parsed because the data is not recognized or invalid for any reason 055 */ 056 <T extends IBaseResource> T parseResource(Class<T> theResourceType, JsonLikeStructure theJsonLikeStructure) throws DataFormatException; 057 058 /** 059 * Parses a resource from a JSON-like data structure 060 * 061 * @param theJsonLikeStructure 062 * The JSON-like structure to parse 063 * @return A parsed resource. Note that the returned object will be an instance of {@link IResource} or 064 * {@link IAnyResource} depending on the specific FhirContext which created this parser. 065 * @throws DataFormatException 066 * If the resource can not be parsed because the data is not recognized or invalid for any reason 067 */ 068 IBaseResource parseResource(JsonLikeStructure theJsonLikeStructure) throws DataFormatException; 069 070}