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
The KeyValuePairConverter<TKey, TValue> is an special case that uses an internal converter that inherits from SmallObjectWithParameterizedConstructorConverter, and that converter validates that the only valid properties are Key and Value.
Therefore when a metadata property $id is also present in the JSON object, the deserializer throws the following, even when the ReferenceHandler feature is set:
System.Text.Json.JsonException : The JSON value could not be converted to System.Collections.Generic.KeyValuePair`2[System.String,System.String]. Path: $ | LineNumber: 2 | BytePositionInLine: 22.
While other types that also use SmallObjectWithParameterizedConstructorConverter throw the following on ReferenceHandler scenarios:
System.NotSupportedException: Reference metadata is not honored when deserializing types using parameterized constructors. See type 'System.Text.Json.Serialization.Tests.ConstructorTests+Employee'. Path: $.$id | LineNumber: 0 | BytePositionInLine: 7.
The text was updated successfully, but these errors were encountered:
Jozkee
changed the title
Avoid throw when a JSON object containing $id tries to deserialize into a KeyValuePair<TKey, TValue>
Fix exception for KeyValuePair<TKey, TValue> when ReferenceHandler is on to match exception thrown by POCOs with parameterized ctor.
Jul 15, 2020
The
KeyValuePairConverter<TKey, TValue>
is an special case that uses an internal converter that inherits fromSmallObjectWithParameterizedConstructorConverter
, and that converter validates that the only valid properties areKey
andValue
.Therefore when a metadata property
$id
is also present in the JSON object, the deserializer throws the following, even when theReferenceHandler
feature is set:While other types that also use
SmallObjectWithParameterizedConstructorConverter
throw the following onReferenceHandler
scenarios:The text was updated successfully, but these errors were encountered: