Skip to content

Commit

Permalink
Merge branch 'develop' into release/5.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
marcovisserFurore committed Apr 26, 2023
2 parents 112938d + 319bbc7 commit 27ebda7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.Json;
using ERR = Hl7.Fhir.Serialization.FhirJsonException;

Expand Down Expand Up @@ -78,7 +77,7 @@ public BaseFhirJsonPocoDeserializer(ModelInspector inspector, FhirJsonPocoDeseri
private const string INSTANCE_VALIDATION_KEY_SUFFIX = ":instance";
private const string PROPERTY_VALIDATION_KEY_SUFFIX = ":property";
private readonly ModelInspector _inspector;

/// <summary>
/// Deserialize the FHIR Json from the reader and create a new POCO object containing the data from the reader.
/// </summary>
Expand All @@ -101,7 +100,7 @@ public bool TryDeserializeResource(ref Utf8JsonReader reader, out Resource? inst

return !state.Errors.HasExceptions;
}

/// <summary>
/// Reads a (subtree) of serialized FHIR Json data into a POCO object.
/// </summary>
Expand Down Expand Up @@ -135,7 +134,7 @@ public bool TryDeserializeObject(Type targetType, ref Utf8JsonReader reader, out
else
throw new ArgumentException($"Can only deserialize into subclasses of class {nameof(Base)}. " + reader.GenerateLocationMessage(), nameof(targetType));
}

internal Resource? DeserializeResourceInternal(ref Utf8JsonReader reader, FhirJsonPocoDeserializerState state, bool stayOnLastToken)
{
if (reader.TokenType != JsonTokenType.StartObject)
Expand Down Expand Up @@ -674,7 +673,7 @@ FhirJsonPocoDeserializerState state
(object? partial, FhirJsonException? error) result = reader.TokenType switch
{
JsonTokenType.Null => new(null, ERR.EXPECTED_PRIMITIVE_NOT_NULL.With(ref reader)),
JsonTokenType.String when string.IsNullOrEmpty(reader.GetString()) => new(null, ERR.PROPERTY_MAY_NOT_BE_EMPTY.With(ref reader)),
JsonTokenType.String when string.IsNullOrEmpty(reader.GetString()) => new(reader.GetString(), ERR.PROPERTY_MAY_NOT_BE_EMPTY.With(ref reader)),
JsonTokenType.String when implementingType == typeof(string) => new(reader.GetString(), null),
JsonTokenType.String when implementingType == typeof(byte[]) =>
!Settings.DisableBase64Decoding ? readBase64(ref reader) : new(reader.GetString(), null),
Expand Down
4 changes: 3 additions & 1 deletion src/Hl7.Fhir.Base/Serialization/FhirJsonException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public class FhirJsonException : CodedException

// The serialization contained a json null where it is not allowed, but a null does not contain data anyway.
internal static readonly FhirJsonException EXPECTED_PRIMITIVE_NOT_NULL = new(EXPECTED_PRIMITIVE_NOT_NULL_CODE, "Expected a primitive value, not a json null.");

// Encountered an empty property, which is illegal, but the empty text is maintained.
internal static readonly FhirJsonException PROPERTY_MAY_NOT_BE_EMPTY = new(PROPERTY_MAY_NOT_BE_EMPTY_CODE, "Properties cannot be empty strings. Either they are absent, or they are present with at least one character of non-whitespace content.");

// These errors signal parsing errors, but the original raw data is retained in the POCO so no data is lost.
Expand Down Expand Up @@ -113,7 +115,7 @@ public class FhirJsonException : CodedException
/// Whether this issue leads to dataloss or not. Recoverable issues mean that all data present in the parsed data could be retrieved and
/// captured in the POCO model, even if the syntax or the data was not fully FHIR compliant.
/// </summary>
internal static bool IsRecoverableIssue(FhirJsonException e) =>
internal static bool IsRecoverableIssue(FhirJsonException e) =>
e.ErrorCode is EXPECTED_PRIMITIVE_NOT_NULL_CODE or
INCORRECT_BASE64_DATA_CODE or
STRING_ISNOTAN_INSTANT_CODE or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class FhirJsonDeserializationTests
[DataRow("enumvalue", null, typeof(UriFormat), null, COVE.INVALID_CODED_VALUE_CODE)]
[DataRow(true, "true", typeof(Enum), null, ERR.UNEXPECTED_JSON_TOKEN_CODE)]
[DataRow("hi!", "hi!", typeof(int), null, ERR.UNEXPECTED_JSON_TOKEN_CODE)]
[DataRow("", null, typeof(string), null, ERR.PROPERTY_MAY_NOT_BE_EMPTY_CODE)]
[DataRow("", "", typeof(string), null, ERR.PROPERTY_MAY_NOT_BE_EMPTY_CODE)]

[DataRow(3, 3, typeof(decimal), null, null)]
[DataRow(3, 3, typeof(uint), null, null)]
Expand Down Expand Up @@ -591,7 +591,6 @@ public void TestRecovery()
ERR.INCOMPATIBLE_SIMPLE_VALUE_CODE,
ERR.EXPECTED_START_OF_ARRAY_CODE,
ERR.UNKNOWN_PROPERTY_FOUND_CODE, // mother is not a property of HumanName
ERR.PROPERTY_MAY_NOT_BE_EMPTY_CODE,
ERR.EXPECTED_PRIMITIVE_NOT_ARRAY_CODE, // family is not an array,
//ERR.PRIMITIVE_ARRAYS_INCOMPAT_SIZE_CODE, // given and _given not the same length
ERR.EXPECTED_PRIMITIVE_NOT_NULL_CODE, // telecom use cannot be null
Expand All @@ -612,6 +611,7 @@ public void TestRecovery()
ERR.NUMBER_CANNOT_BE_PARSED_CODE, // multipleBirthInteger should not be a float (3.14)
ERR.INCORRECT_BASE64_DATA_CODE,
ERR.ARRAYS_CANNOT_BE_EMPTY_CODE,
ERR.PROPERTY_MAY_NOT_BE_EMPTY_CODE,
ERR.OBJECTS_CANNOT_BE_EMPTY_CODE
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"given": [ "This should be an array" ]
},
{
"id": "anothername",
"use": "usual",
"given": [ "Eveline", null ],
"_given": [
Expand Down Expand Up @@ -302,7 +303,7 @@
],
"managingOrganization": {
"reference": "Organization/1",
"display": "ACME Healthcare, Inc"
"display": ""
},
"link": [ {} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"mother": "this does not exist"
},
{
"id": "",
"id": "anothername",
"use": "usual",
"family": [ "error: array is unexpected here" ],
"given": [ "Eveline" ],
Expand Down Expand Up @@ -329,7 +329,7 @@
],
"managingOrganization": {
"reference": "Organization/1",
"display": "ACME Healthcare, Inc"
"display": ""
},
"link": [
{
Expand Down

0 comments on commit 27ebda7

Please sign in to comment.