
Package ca.uhn.fhir.parser
Class JsonParser
java.lang.Object
ca.uhn.fhir.parser.BaseParser
ca.uhn.fhir.parser.JsonParser
- All Implemented Interfaces:
IJsonLikeParser,IParser
This class is the FHIR JSON parser/encoder. Users should not interact with this class directly, but should use
FhirContext.newJsonParser() to get an instance.-
Nested Class Summary
Nested classes/interfaces inherited from class ca.uhn.fhir.parser.BaseParser
BaseParser.CompositeChildElement -
Field Summary
Fields inherited from class ca.uhn.fhir.parser.BaseParser
RESOURCE_CREATED_BY_PARSER -
Constructor Summary
ConstructorsConstructorDescriptionJsonParser(FhirContext theContext, IParserErrorHandler theParserErrorHandler) Do not use this constructor, the recommended way to obtain a new instance of the JSON parser is to invokeFhirContext.newJsonParser(). -
Method Summary
Modifier and TypeMethodDescriptionvoiddoEncodeResourceToJsonLikeWriter(IBaseResource theResource, BaseJsonLikeWriter theEventWriter, ca.uhn.fhir.parser.BaseParser.EncodeContext theEncodeContext) protected voiddoEncodeResourceToWriter(IBaseResource theResource, Writer theWriter, ca.uhn.fhir.parser.BaseParser.EncodeContext theEncodeContext) protected voiddoEncodeToWriter(IBase theElement, Writer theWriter, ca.uhn.fhir.parser.BaseParser.EncodeContext theEncodeContext) protected voiddoParseIntoComplexStructure(Reader theSource, IBase theTarget) <T extends IBaseResource>
TdoParseResource(Class<T> theResourceType, JsonLikeStructure theJsonStructure) <T extends IBaseResource>
TdoParseResource(Class<T> theResourceType, Reader theReader) voidencodeResourceToJsonLikeWriter(IBaseResource theResource, BaseJsonLikeWriter theJsonLikeWriter) Which encoding does this parser instance produce?parseResource(JsonLikeStructure theJsonLikeStructure) Parses a resource from a JSON-like data structure<T extends IBaseResource>
TparseResource(Class<T> theResourceType, JsonLikeStructure theJsonLikeStructure) Parses a resource from a JSON-like data structuresetPrettyPrint(boolean thePrettyPrint) Sets the "pretty print" flag, meaning that the parser will encode resources with human-readable spacing and newlines between elements instead of condensing output as much as possible.Methods inherited from class ca.uhn.fhir.parser.BaseParser
compositeChildIterator, containResourcesInReferences, encodeResourceToString, encodeResourceToWriter, encodeResourceToWriter, encodeToString, encodeToWriter, encodeToWriter, extractMetadataListNotNull, fixContainedResourceId, getCompositeElementId, getContext, getDontStripVersionsFromReferencesAtPaths, getEncodeForceResourceId, getErrorHandler, getExtensionMetadataKeys, getExtensionUrl, getMetaTagsForEncoding, getPreferTypes, getProfileTagsForEncoding, getServerBaseUrl, getStripVersionsFromReferences, getSuppressNarratives, isChildContained, isEncodeElementsAppliesToChildResourcesOnly, isOmitResourceId, isSummaryMode, isSuppressNarratives, parseInto, parseResource, parseResource, parseResource, parseResource, parseResource, parseResource, preProcessValues, setDontEncodeElements, setDontStripVersionsFromReferencesAtPaths, setDontStripVersionsFromReferencesAtPaths, setEncodeElements, setEncodeElementsAppliesToChildResourcesOnly, setEncodeForceResourceId, setOmitResourceId, setOverrideResourceIdWithBundleEntryFullUrl, setParserErrorHandler, setPreferTypes, setServerBaseUrl, setStripVersionsFromReferences, setSummaryMode, setSuppressNarratives, shouldAddSubsettedTag, shouldEncodePath, shouldEncodeResource, shouldEncodeResourceId, shouldEncodeResourceMeta, throwExceptionForUnknownChildTypeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ca.uhn.fhir.parser.IParser
encodeResourceToString, encodeResourceToWriter, encodeToString, encodeToWriter, getDontStripVersionsFromReferencesAtPaths, getEncodeForceResourceId, getPreferTypes, getStripVersionsFromReferences, isEncodeElementsAppliesToChildResourcesOnly, isOmitResourceId, isSummaryMode, parseInto, parseInto, parseResource, parseResource, parseResource, parseResource, parseResource, parseResource, setDontEncodeElements, setDontEncodeElements, setDontStripVersionsFromReferencesAtPaths, setDontStripVersionsFromReferencesAtPaths, setEncodeElements, setEncodeElements, setEncodeElementsAppliesToChildResourcesOnly, setEncodeForceResourceId, setOmitResourceId, setOverrideResourceIdWithBundleEntryFullUrl, setParserErrorHandler, setPreferTypes, setServerBaseUrl, setStripVersionsFromReferences, setSummaryMode, setSuppressNarratives
-
Constructor Details
-
JsonParser
Do not use this constructor, the recommended way to obtain a new instance of the JSON parser is to invokeFhirContext.newJsonParser().- Parameters:
theParserErrorHandler-
-
-
Method Details
-
doEncodeResourceToJsonLikeWriter
public void doEncodeResourceToJsonLikeWriter(IBaseResource theResource, BaseJsonLikeWriter theEventWriter, ca.uhn.fhir.parser.BaseParser.EncodeContext theEncodeContext) throws IOException - Throws:
IOException
-
doEncodeResourceToWriter
protected void doEncodeResourceToWriter(IBaseResource theResource, Writer theWriter, ca.uhn.fhir.parser.BaseParser.EncodeContext theEncodeContext) throws IOException - Specified by:
doEncodeResourceToWriterin classBaseParser- Throws:
IOException
-
doEncodeToWriter
protected void doEncodeToWriter(IBase theElement, Writer theWriter, ca.uhn.fhir.parser.BaseParser.EncodeContext theEncodeContext) throws IOException, DataFormatException - Overrides:
doEncodeToWriterin classBaseParser- Throws:
IOExceptionDataFormatException
-
doParseIntoComplexStructure
- Overrides:
doParseIntoComplexStructurein classBaseParser
-
doParseResource
- Specified by:
doParseResourcein classBaseParser
-
doParseResource
public <T extends IBaseResource> T doParseResource(Class<T> theResourceType, JsonLikeStructure theJsonStructure) -
encodeResourceToJsonLikeWriter
public void encodeResourceToJsonLikeWriter(IBaseResource theResource, BaseJsonLikeWriter theJsonLikeWriter) throws IOException, DataFormatException - Specified by:
encodeResourceToJsonLikeWriterin interfaceIJsonLikeParser- Throws:
IOExceptionDataFormatException
-
getEncoding
Description copied from interface:IParserWhich encoding does this parser instance produce?- Specified by:
getEncodingin interfaceIParser
-
parseResource
public <T extends IBaseResource> T parseResource(Class<T> theResourceType, JsonLikeStructure theJsonLikeStructure) throws DataFormatException Description copied from interface:IJsonLikeParserParses a resource from a JSON-like data structure- Specified by:
parseResourcein interfaceIJsonLikeParser- Parameters:
theResourceType- The resource type to use. This can be used to explicitly specify a class which extends a built-in type (e.g. a custom type extending the default Patient class)theJsonLikeStructure- The JSON-like structure to parse- Returns:
- A parsed resource
- Throws:
DataFormatException- If the resource can not be parsed because the data is not recognized or invalid for any reason
-
parseResource
public IBaseResource parseResource(JsonLikeStructure theJsonLikeStructure) throws DataFormatException Description copied from interface:IJsonLikeParserParses a resource from a JSON-like data structure- Specified by:
parseResourcein interfaceIJsonLikeParser- Parameters:
theJsonLikeStructure- The JSON-like structure to parse- Returns:
- A parsed resource. Note that the returned object will be an instance of
IResourceorIAnyResourcedepending on the specific FhirContext which created this parser. - Throws:
DataFormatException- If the resource can not be parsed because the data is not recognized or invalid for any reason
-
setPrettyPrint
Description copied from interface:IParserSets the "pretty print" flag, meaning that the parser will encode resources with human-readable spacing and newlines between elements instead of condensing output as much as possible.- Specified by:
setPrettyPrintin interfaceIParser- Parameters:
thePrettyPrint- The flag- Returns:
- Returns an instance of
thisparser so that method calls can be chained together
-