Quantcast
Channel: ASP.NET MVC / Web API / Web Pages
Viewing all articles
Browse latest Browse all 7925

Commented Issue: Global Json serializer settings aren't used when posting to server [609]

$
0
0
And the culprit is TryReadQueryAs method of UriExtensions that just instantiates a new JsonSerializer that doesn't use global serializer settings, defined in config.Formatters.JsonFormatter.SerializerSettings. One of the consequences of this, is that I can't bind derived classes to base classes, using JSON.NET TypeNameHandling. Please fix this ASAP.

For example:
I serialize an Employee, and since i set TypeNameHandling to auto, it will add $type="Employee" to the serialized json. Then when I send that json back to some method that expects class Person, it will bind it to person (Employee properties will not get bound) and will ignore the type, because the said method doesn't use global settings(where I set TypeNameHandling). And hence uses TypeNameHandling.None.

So solution is just use the global settings when you instatiate the serializer in TryReadQueryAs method
Comments: Sorry!...my previous comment is looking ugly due to Codeplex's editor...

Viewing all articles
Browse latest Browse all 7925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>