You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The new System.Text.Json based deserializer silently accepts duplicate choice types if they are of different types. The old deserializer fails with an exception. From what I observed, it will use the first property encountered and ignore the rest.
To Reproduce
Reproduction code:
varscenario=""" { "resourceType": "Patient", "deceasedBoolean": true, "deceasedDateTime": "2022" } """;varjsonSerializerOptions=newJsonSerializerOptions().ForFhir();// successfully parses with new deserializervarpatient=JsonSerializer.Deserialize<Patient>(scenario,jsonSerializerOptions);Console.WriteLine("New deserializer: "+patient.ToJson());// fails with old jsonParsertry{patient=newFhirJsonParser().Parse<Patient>(scenario);}catch(Exceptionex){Console.WriteLine(ex.ToString());}
Output:
New deserializer: {"resourceType":"Patient","deceasedBoolean":"2022"}
System.FormatException: While building a POCO: Element 'deceased' must not repeat (at Patient.deceasedDateTime[0])
at Hl7.Fhir.Serialization.ComplexTypeReader.RaiseFormatError(String message, String location)
at Hl7.Fhir.Serialization.ComplexTypeReader.read(ClassMapping mapping, IEnumerable`1 members, Base existing)
at Hl7.Fhir.Serialization.ComplexTypeReader.Deserialize(ClassMapping mapping, Base existing)
at Hl7.Fhir.Serialization.PocoBuilder.<>c__DisplayClass9_0.<BuildFrom>g__build|0()
at Hl7.Fhir.Serialization.PocoBuilder.BuildFrom(ITypedElement source)
at Hl7.Fhir.Serialization.PocoBuilder.BuildFrom(ISourceNode source, ClassMapping mapping)
at Hl7.Fhir.Serialization.PocoBuilder.BuildFrom(ISourceNode source, Type dataType)
at Hl7.Fhir.ElementModel.PocoBuilderExtensions.ToPoco(ISourceNode source, ModelInspector inspector, Type pocoType, PocoBuilderSettings settings)
at Hl7.Fhir.Serialization.BaseFhirParser.Parse(ISourceNode node, Type type)
at Hl7.Fhir.Serialization.FhirJsonParser.Parse(String json, Type dataType)
at Hl7.Fhir.Serialization.FhirJsonParser.Parse[T](String json)
at Program.<Main>$(String[] args) in D:\repos\ConsoleApp1\Program.cs:line 26
Expected behavior
An exception should be thrown similar to the old deserializer.
Version used:
Version: 5.5.0
The text was updated successfully, but these errors were encountered:
Describe the bug
The new System.Text.Json based deserializer silently accepts duplicate choice types if they are of different types. The old deserializer fails with an exception. From what I observed, it will use the first property encountered and ignore the rest.
To Reproduce
Reproduction code:
Output:
Expected behavior
An exception should be thrown similar to the old deserializer.
Version used:
The text was updated successfully, but these errors were encountered: