序列化子对象列表的JSON.NET始终返回基础对象列表

时间:2011-09-05 18:54:50

标签: c# .net json.net

我做错了什么?

[JsonObject(MemberSerialization.OptOut)]
public class Parent
{
    public int ParentID {get;set;}
}

[JsonObject(MemberSerialization.OptOut)]
public class Child
{
    public int ChildID { get; set;}
}

[JsonObject(MemberSerialization.OptOut)]
public class Container
{
    [JsonProperty(TypeNameHandling = TypeNameHandling.All)]  
    public List<Parent> Objects {get; set;}
}

ContainerInstance.Objects.Add(new Child());  
var mem = new MemoryStream();
var writer = new BsonWriter(mem);
var reader = new BsonReader(mem);
var serializer = new JsonSerializer();
serializer.TypeNameAssemblyFormat =  
    System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Full;

serializer.Serialize(writer, ContainerInstance);
mem.Position = 0;
var deserializedContainerInstance = serializer.Deserialize<Nute>(reader);

// WHERE IS THE CHILDID?
deserializedContainerInstance.Object; 

0 个答案:

没有答案