Package ca.uhn.fhir.parser
Class LenientErrorHandler
java.lang.Object
ca.uhn.fhir.parser.LenientErrorHandler
- All Implemented Interfaces:
IParserErrorHandler
The default error handler, which logs issues but does not abort parsing, with only two exceptions:
The invalidValue(ca.uhn.fhir.parser.IParserErrorHandler.IParseLocation, String, String)
method will throw a DataFormatException
by default since ignoring this type of error
can lead to data loss (since invalid values are silently ignored). See
setErrorOnInvalidValue(boolean)
for information on this.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface ca.uhn.fhir.parser.IParserErrorHandler
IParserErrorHandler.IParseLocation
-
Constructor Summary
ConstructorDescriptionConstructor which configures this handler to log all errorsLenientErrorHandler
(boolean theLogErrors) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
Invoked when a contained resource is parsed that has no ID specified (and is therefore invalid)static String
createIncorrectJsonTypeMessage
(String theElementName, BaseJsonLikeValue.ValueType theExpected, BaseJsonLikeValue.ScalarType theExpectedScalarType, BaseJsonLikeValue.ValueType theFound, BaseJsonLikeValue.ScalarType theFoundScalarType) If this method is called, both invalid resource extensions and invalid attribute values will set to simply logging errors.void
An extension contains both a value and at least one nested extensionvoid
incorrectJsonType
(IParserErrorHandler.IParseLocation theLocation, String theElementName, BaseJsonLikeValue.ValueType theExpected, BaseJsonLikeValue.ScalarType theExpectedScalarType, BaseJsonLikeValue.ValueType theFound, BaseJsonLikeValue.ScalarType theFoundScalarType) Invoked if the wrong type of element is found while parsing JSON.void
invalidValue
(IParserErrorHandler.IParseLocation theLocation, String theValue, String theError) The parser detected an attribute value that was invalid (such as: empty "" values are not permitted)boolean
If set tofalse
(default istrue
) invalid extensions will be logged.boolean
If set tofalse
(default istrue
) invalid values will be logged.void
missingRequiredElement
(IParserErrorHandler.IParseLocation theLocation, String theElementName) Resource was missing a required elementsetErrorOnInvalidExtension
(boolean theErrorOnInvalidExtension) If set tofalse
(default istrue
) invalid extensions will be logged.setErrorOnInvalidValue
(boolean theErrorOnInvalidValue) If set tofalse
(default istrue
) invalid values will be logged.void
unexpectedRepeatingElement
(IParserErrorHandler.IParseLocation theLocation, String theElementName) Invoked when an element repetition (e.g.void
unknownAttribute
(IParserErrorHandler.IParseLocation theLocation, String theElementName) Invoked when an unknown element is found in the document.void
unknownElement
(IParserErrorHandler.IParseLocation theLocation, String theElementName) Invoked when an unknown element is found in the document.void
unknownReference
(IParserErrorHandler.IParseLocation theLocation, String theReference) Resource contained a reference that could not be resolved and needs to be resolvable (e.g.
-
Constructor Details
-
LenientErrorHandler
public LenientErrorHandler()Constructor which configures this handler to log all errors -
LenientErrorHandler
Constructor- Parameters:
theLogErrors
- Should errors be logged?- Since:
- 1.2
-
-
Method Details
-
containedResourceWithNoId
Description copied from interface:IParserErrorHandler
Invoked when a contained resource is parsed that has no ID specified (and is therefore invalid)- Specified by:
containedResourceWithNoId
in interfaceIParserErrorHandler
- Parameters:
theLocation
- The location in the document. WILL ALWAYS BE NULL currently, as this is not yet implemented, but this parameter is included so that locations can be added in the future without changing the API.
-
incorrectJsonType
public void incorrectJsonType(IParserErrorHandler.IParseLocation theLocation, String theElementName, BaseJsonLikeValue.ValueType theExpected, BaseJsonLikeValue.ScalarType theExpectedScalarType, BaseJsonLikeValue.ValueType theFound, BaseJsonLikeValue.ScalarType theFoundScalarType) Description copied from interface:IParserErrorHandler
Invoked if the wrong type of element is found while parsing JSON. For example if a given element is expected to be a JSON Object and is a JSON array- Specified by:
incorrectJsonType
in interfaceIParserErrorHandler
- Parameters:
theLocation
- The location in the document. Note that this may benull
as the ParseLocation feature is experimental. Use with caution, as the API may change.theElementName
- The name of the element that was found.theExpected
- The datatype that was expected at this locationtheExpectedScalarType
- If theExpectedValueType isBaseJsonLikeValue.ValueType.SCALAR
, this is the specific scalar type expected. Otherwise this parameter will be null.theFound
- The datatype that was found at this locationtheFoundScalarType
- If theFoundValueType isBaseJsonLikeValue.ValueType.SCALAR
, this is the specific scalar type found. Otherwise this parameter will be null.
-
invalidValue
public void invalidValue(IParserErrorHandler.IParseLocation theLocation, String theValue, String theError) Description copied from interface:IParserErrorHandler
The parser detected an attribute value that was invalid (such as: empty "" values are not permitted)- Specified by:
invalidValue
in interfaceIParserErrorHandler
- Parameters:
theLocation
- The location in the document. Note that this may benull
as the ParseLocation feature is experimental. Use with caution, as the API may change.theValue
- The actual valuetheError
- A description of why the value was invalid
-
isErrorOnInvalidValue
If set tofalse
(default istrue
) invalid values will be logged. By default, invalid attribute values cause this error handler to throw aDataFormatException
(unlike other methods in this class which default to simply logging errors).Note that empty values (e.g.
""
) will not lead to an error when this is set totrue
, only invalid values (e.g. a gender code offoo
)- See Also:
-
isErrorOnInvalidExtension
If set tofalse
(default istrue
) invalid extensions will be logged. By default, invalid resource extensions cause this error handler to throw aDataFormatException
(unlike other methods in this class which default to simply logging errors).- See Also:
-
missingRequiredElement
public void missingRequiredElement(IParserErrorHandler.IParseLocation theLocation, String theElementName) Description copied from interface:IParserErrorHandler
Resource was missing a required element- Specified by:
missingRequiredElement
in interfaceIParserErrorHandler
- Parameters:
theLocation
- The location in the document. Note that this may benull
as the ParseLocation feature is experimental. Use with caution, as the API may change.theElementName
- The missing element name
-
setErrorOnInvalidValue
If set tofalse
(default istrue
) invalid values will be logged. By default, invalid attribute values cause this error handler to throw aDataFormatException
(unlike other methods in this class which default to simply logging errors).Note that empty values (e.g.
""
) will not lead to an error when this is set totrue
, only invalid values (e.g. a gender code offoo
)- Returns:
- Returns a reference to
this
for easy method chaining - See Also:
-
setErrorOnInvalidExtension
If set tofalse
(default istrue
) invalid extensions will be logged. By default, invalid resource extensions cause this error handler to throw aDataFormatException
(unlike other methods in this class which default to simply logging errors).- Returns:
- Returns a reference to
this
for easy method chaining - See Also:
-
disableAllErrors
If this method is called, both invalid resource extensions and invalid attribute values will set to simply logging errors. -
unexpectedRepeatingElement
public void unexpectedRepeatingElement(IParserErrorHandler.IParseLocation theLocation, String theElementName) Description copied from interface:IParserErrorHandler
Invoked when an element repetition (e.g. a second repetition of something) is found for a field which is non-repeating.- Specified by:
unexpectedRepeatingElement
in interfaceIParserErrorHandler
- Parameters:
theLocation
- The location in the document. Note that this may benull
as the ParseLocation feature is experimental. Use with caution, as the API may change.theElementName
- The name of the element that was found.
-
unknownAttribute
Description copied from interface:IParserErrorHandler
Invoked when an unknown element is found in the document.- Specified by:
unknownAttribute
in interfaceIParserErrorHandler
- Parameters:
theLocation
- The location in the document. Note that this may benull
as the ParseLocation feature is experimental. Use with caution, as the API may change.theElementName
- The name of the attribute that was found.
-
unknownElement
Description copied from interface:IParserErrorHandler
Invoked when an unknown element is found in the document.- Specified by:
unknownElement
in interfaceIParserErrorHandler
- Parameters:
theLocation
- The location in the document. Note that this may benull
as the ParseLocation feature is experimental. Use with caution, as the API may change.theElementName
- The name of the element that was found.
-
unknownReference
Description copied from interface:IParserErrorHandler
Resource contained a reference that could not be resolved and needs to be resolvable (e.g. because it is a local reference to an unknown contained resource)- Specified by:
unknownReference
in interfaceIParserErrorHandler
- Parameters:
theLocation
- The location in the document. Note that this may benull
as the ParseLocation feature is experimental. Use with caution, as the API may change.theReference
- The actual invalid reference (e.g. "#3")
-
extensionContainsValueAndNestedExtensions
public void extensionContainsValueAndNestedExtensions(IParserErrorHandler.IParseLocation theLocation) Description copied from interface:IParserErrorHandler
An extension contains both a value and at least one nested extension- Specified by:
extensionContainsValueAndNestedExtensions
in interfaceIParserErrorHandler
-
createIncorrectJsonTypeMessage
public static String createIncorrectJsonTypeMessage(String theElementName, BaseJsonLikeValue.ValueType theExpected, BaseJsonLikeValue.ScalarType theExpectedScalarType, BaseJsonLikeValue.ValueType theFound, BaseJsonLikeValue.ScalarType theFoundScalarType)
-