Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

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: That is not a bug, it's a feature ;) If you use Auto, it will only serialize type name, if declared and instantiated type are different e.g. Person p = new Employee() { Id = 1, Name = "Scott", DepartmentName = "ASP.NET" };

Viewing all articles
Browse latest Browse all 7215

Trending Articles



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