Quantcast
Channel: Json.NET
Viewing all articles
Browse latest Browse all 1767

Closed Issue: TypeNameHandling.Auto and Serializing Derived Type [23891]

$
0
0
Scenario:

```
public abstract class Entity { ... }
public class Cat : Entity { ... }
public class Dog : Entity { ... }
```

It would be nice if the following were to happen with TypeNameHandling.Auto:

```
JsonSerializer serializer = new JsonSerializer();

//I would expect $type for the Cat to be written in this case:
serializer.Serialize{Entity}(new Cat());

//But not in this case:
serializer.Serialize{Cat}(new Cat());
```
NOTE: Forgive the curly brackets, CodePlex Is eating my less than and greater than characters

The assumption being that if I have some abstraction in the layer that does my serialization, I'm probably going to have that same abstraction on the deserialization. Currently this doesn't work and I'm forced to switch to TypeNameHandling.All to get the $type of the top-level object written so it can be deserialized correctly on the other side.

Thoughts?
Comments: I've modified your code but the functionality is the same.

Viewing all articles
Browse latest Browse all 1767

Trending Articles



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