DeserializeKeyValuePair - Should ignore "__type" property

When serializing and then deserializing KVPs and emitting the Type information, if any key besides “key” or “value” is found, it throws. I think the code should ignore “__type”, no?

Below is an example of JSON serialized with type info that’s causing the throw.

{"__type":"System.Collections.Generic.KeyValuePair`2[[System.String, System.Private.CoreLib],[System.String, System.Private.CoreLib]], System.Private.CoreLib","Key":"Yes","Value":"Yes"}

Resolved in this commit, this change is available from latest v5.10.3+ that’s now on MyGet.

FYI the JSON.parse() JS Util is generally better suited for parsing adhoc JSON as you don’t need to specify the Type and it preserves the type of the JSON instead of coercing values into a string.

Awesome, thanks.

FWIW I’m parsing adhoc (polymorphic) JSON that, deep down, has a KVP property in it, which is what’s causing the problem.

Is there a way to say “turn on __type for certain types but not others” ?

No, although my recommendation would instead be focusing on removing reliance on it.

1 Like