Deserialization behavior reference
This page is a reference for the exact behavior of the SDK 6 deserializers when they encounter an irregularity. It complements Error handling and deserialization modes, which explains the concepts; here we list the individual issue codes, their severity, and — importantly — what the deserializer does with the data in each case.
All codes are stable: the ErrorCode of an issue never changes between SDK versions, so it is safe to refer to these constants in your own error handling. The constants live on FhirJsonException, FhirXmlException and CodedValidationException; the lists below mirror those classes.
JSON syntax issues
These are raised by the JSON parser as FhirJsonException. Unless marked Fatal, all data is preserved.
Code |
Constant |
Severity |
What happens to the data |
|---|---|---|---|
|
|
Error |
The non-string value is used as the type name and the resource is stored as a |
|
|
Error |
With no type to resolve, the resource is stored as an (unnamed) |
|
|
Error |
The |
|
|
Error |
The type is guessed and the value is stored using a |
|
|
Error |
The empty object holds no data; it is skipped. |
|
|
Error |
The empty array holds no data; it is skipped. |
|
|
Error |
The nulls are left in place; there was no data to capture. |
|
|
Fatal |
The duplicates are merged into a single element; a conflicting primitive value keeps the first occurrence, so the later data is dropped. |
|
|
Error |
The nested array is flattened into its parent, so no data is lost. |
|
|
Error |
The primitive cannot fit the complex element, so it is preserved in that element’s overflow under the key |
|
|
Error |
The object is deserialized into the primitive: |
|
|
Error |
The underscore form is only valid for primitives; here it is ignored and the complex value is parsed normally. |
|
|
Error |
The |
Note
When a value cannot be placed in its typed property — as with JSON131 and JSON132 — the generated POCO keeps the value in the element’s overflow and leaves the typed property empty. The data is therefore not lost, but it must be read through the overflow (see Dynamic Access to data), Base.HasOverflow becomes true, and the model validator additionally reports this as an overflow-causing PROPERTY_TYPE_MISMATCH (PVAL127).
Note
The JSON133 and JSON134 codes concern FHIR’s underscore form for primitives. In FHIR JSON a primitive element such as name may be accompanied by a _name companion that carries its id and extension; the two are merged into a single element. The companion is only valid on a primitive (otherwise JSON133) and must be a JSON object (otherwise JSON134).
XML syntax issues
These are raised by the XML parser as FhirXmlException. XML has concerns JSON does not — namespaces, element ordering, and the attribute/element distinction — so it has a few more codes.
Code |
Constant |
Severity |
What happens to the data |
|---|---|---|---|
|
|
Error |
The element is parsed as though it were in the FHIR namespace. |
|
|
Error |
The type is guessed and the value is stored using a |
|
|
Error |
The narrative XHTML is still read and captured. |
|
|
Error |
The element is parsed normally; order does not affect the result. |
|
|
Fatal |
Only one resource fits in a container, so the extra resources are lost. |
|
|
Fatal |
The attribute cannot be represented on a container, so its data is lost. |
|
|
Error |
The element is parsed anyway, ignoring the namespace. |
|
|
Fatal |
The node cannot be represented in the model, so its content is lost. |
|
|
Error |
The attribute value is parsed anyway, ignoring the namespace. |
|
|
Error |
The value is still added to the (repeating) element. |
|
|
Warning |
The attribute is ignored; it carries no data. |
|
|
Error |
The container holds no resource; there is nothing to capture. |
|
|
Error |
The element’s content is captured into the value anyway. |
|
|
Error |
The attribute’s content is captured into the element anyway. |
|
|
Warning |
The whitespace is trimmed and the trimmed value is kept. |
Differences between the XML and JSON deserializers
The two formats share the same model and modes, but a few behaviors are format-specific:
Namespaces and ordering are XML-only concerns (
XML101,XML107,XML109,XML112,XML114).The attribute vs. element distinction (
XML124,XML125) has no JSON equivalent.JSON’s underscore form for primitive extensions (
JSON133,JSON134) and its duplicate-property problem (JSON129) have no XML equivalent.
Otherwise both produce the same model-validation issues and obey the same modes.
Model-validation issues
Note
These issues come from the validator that runs during parsing (see Validation during parsing), not from the parser itself. They are covered in depth in the validation chapter; the table here is a quick reference for how they surface during deserialization.
These are raised as CodedValidationException (codes PVAL…). The ones marked overflow in the last column are the issues that indicate data did not fit a typed property and was placed in overflow — in other words, if none of these were raised, the POCO can be used without checking Base.Overflow.
Code |
Constant |
Causes overflow |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
yes |
|
|
|
|
|
yes |
|
|
yes |
|
|
yes |
|
|
yes |
|
|
|
|
|
|
|
|
yes |
|
|
yes |
|
|
|
|
|
Of these, the ones allowed through in BackwardsCompatible mode — because a newer FHIR version could legitimately introduce them — are INVALID_CODED_VALUE, UNKNOWN_ELEMENT, CHOICE_TYPE_NOT_ALLOWED and UNKNOWN_RESOURCE_TYPE.
