Describe the bug
The System.Text.Json Fhir deserializer throws an exception when numeric fields are quoted unlike in the Newtonsoft serializer.
This is breaking our automated UI tests after upgrading to the latest version of the SDK and using the newer serializer.
Setting the NumberHandling property in the JsonSerializerOptions to AllowReadingFromString has no effect.
To Reproduce
Create the following resource:
{
"resourceType": "Patient",
"multipleBirthInteger": "3",
}
Exception thrown:
Hl7.Fhir.Serialization.DeserializationFailedException: 'One or more errors occurred. (Expecting a Int32, but found a json string with value '3'. At line 15, position 30.)'
at Hl7.Fhir.Serialization.FhirJsonPocoDeserializer.DeserializeResource(Utf8JsonReader& reader)
at Hl7.Fhir.Serialization.FhirJsonConverter`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadCore[TValue](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadCore[TValue](JsonReaderState& readerState, Boolean isFinalBlock, ReadOnlySpan`1 buffer, JsonSerializerOptions options, ReadStack& state, JsonConverter converterBase)
at System.Text.Json.JsonSerializer.ContinueDeserialize[TValue](ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack, JsonConverter converter, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.<ReadAllAsync>d__65`1.MoveNext()
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at Ihis.FhirEngine.Core.Utility.Serialization.SystemTextJsonFhirJsonSerializationUtility.<DeserializeAsync>d__6`1.MoveNext() in C:\Users\donnr\Source\Repos\FhirEngine\src\Ihis.FhirEngine.Core\Utility\Serialization\SystemTextJsonFhirJsonSerializationUtility.cs:line 47
Expected behavior
System.Text.Json should also be able to parse successfully when NumberHandling is set to AllowReadingFromString
Version used:
- FHIR Version: R4
- Version: 4.2.1
Describe the bug
The System.Text.Json Fhir deserializer throws an exception when numeric fields are quoted unlike in the Newtonsoft serializer.
This is breaking our automated UI tests after upgrading to the latest version of the SDK and using the newer serializer.
Setting the NumberHandling property in the JsonSerializerOptions to
AllowReadingFromStringhas no effect.To Reproduce
Create the following resource:
{ "resourceType": "Patient", "multipleBirthInteger": "3", }Exception thrown:
Expected behavior
System.Text.Json should also be able to parse successfully when NumberHandling is set to AllowReadingFromString
Version used: