Diccionario de serialización / deserialización de objetos con JSON.NET
Estoy tratando de serializar / deserializar unDictionary<string, object>
que parece funcionar bien si el objeto es de tipo simple pero no funciona cuando el objeto es más complejo.
Tengo esta clase:
public class UrlStatus
{
public int Status { get; set; }
public string Url { get; set; }
}
En mi diccionario agrego unList<UrlStatus>
con una tecla de "Redirigir cadena" y algunas cadenas simples con las teclas "Estado", "Url", "URL principal". La cadena que estoy recuperando de JSON.Net se ve así:
{"$type":"System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib","Status":"OK","Url":"http://www.ehow.com/m/how_5615409_create-pdfs-using-bean.html","Parent Url":"http://www.ehow.com/mobilearticle35.xml","Redirect Chain":[{"$type":"Demand.TestFramework.Core.Entities.UrlStatus, Demand.TestFramework.Core","Status":301,"Url":"http://www.ehow.com/how_5615409_create-pdfs-using-bean.html"}]}
El código que estoy usando para serializar se ve así:
JsonConvert.SerializeObject(collection, Formatting.None, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Objects,
TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
});
para deserializar lo que estoy haciendo:
JsonConvert.DeserializeObject<T>(collection, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Objects,
TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple,
});
El Diccionario vuelve bien, todas las cadenas vuelven bien, pero la Lista no se deserializa correctamente. Simplemente vuelve como
{[
{
"$type": "XYZ.TestFramework.Core.Entities.UrlStatus, XYZ.TestFramework.Core",
"Status": 301,
"Url": "/how_5615409_create-pdfs-using-bean.html"
}
]}
Por supuesto, puedo volver a desrailizar esta cadena y obtengo el objeto correcto, pero parece que JSON.Net debería haberlo hecho por mí. Claramente estoy haciendo algo mal, pero no sé qué es.