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
{{ message }}
Repository navigation
DictionaryKeyPolicy only works for deserialization but not serialization #30008
DictionaryKeyPolicy only works for deserialization but not serialization. When serializing ValidationProblemDetails the keys aren't converting to camelCase
Why is DictionaryKeyPolicy being used for deserialization? It should only be used for serialization.
Using the naming policy on deserialization results in dictionary keys being consistent regardless of input, which can happen when not non-round tripping the JSON. For example with a camel-casing policy {"Foo" : 1} and {"foo":1} will result in the same dictionary key of foo. This may be required for any logic using the keys.
If we don't apply the policy during deserialization but that semantics is necessary, the "workaround" would be to have the POCO instantiate a case-insensitive dictionary.
Skipping calling on deserialize should help improve performance a bit...
What are the scenarios where leaving the keys "as-is" during deserialization is desired?
I'm sure we had discussed this. Naming policies are one way operations. When you convert pascal case "ID" to camel case "id" there is no way to reliably convert back again. Was the original string "ID" or "Id"?
That is why there is only one convert method on the type rather than ConvertFrom/ConvertTo.
Activity
ahsonkhan commentedon Jun 25, 2019
Can you share a sample repro of the issue you are seeing?
cc @steveharter, @pranavkm, @layomia
davidikin45 commentedon Jun 25, 2019
ahsonkhan commentedon Jun 25, 2019
pranavkm commentedon Jun 25, 2019
@ahsonkhan this would be the scenario:
The expectation here is that serialization would also honor the dictionary key policy.
ahsonkhan commentedon Jun 25, 2019
We should also verify that
PropertyNamingPolicyis working correctly for serialization.JamesNK commentedon Jun 28, 2019
Why is DictionaryKeyPolicy being used for deserialization? It should only be used for serialization.
steveharter commentedon Jul 1, 2019
Using the naming policy on deserialization results in dictionary keys being consistent regardless of input, which can happen when not non-round tripping the JSON. For example with a camel-casing policy
{"Foo" : 1}and{"foo":1}will result in the same dictionary key offoo. This may be required for any logic using the keys.If we don't apply the policy during deserialization but that semantics is necessary, the "workaround" would be to have the POCO instantiate a case-insensitive dictionary.
Skipping calling on deserialize should help improve performance a bit...
What are the scenarios where leaving the keys "as-is" during deserialization is desired?
steveharter commentedon Jul 1, 2019
cc @pranavkm @rynowak
JamesNK commentedon Jul 1, 2019
I'm sure we had discussed this. Naming policies are one way operations. When you convert pascal case "ID" to camel case "id" there is no way to reliably convert back again. Was the original string "ID" or "Id"?
That is why there is only one convert method on the type rather than ConvertFrom/ConvertTo.