-Fixed ItemConverter not being used when serializing dictionaries

-Fixed an incorrect object being passed to the Error event when serializing dictionaries
This commit is contained in:
James Newton-King
2012-06-04 19:01:17 +12:00
parent ab8b06c47b
commit 0ba52bbf13
2 changed files with 74 additions and 43 deletions
@@ -6465,6 +6465,37 @@ Parameter name: value",
Assert.IsNotNull(uri);
Assert.AreEqual(new Uri("/path?query#hash", UriKind.RelativeOrAbsolute), uri);
}
public class MyConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteValue("X");
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return "X";
}
public override bool CanConvert(Type objectType)
{
return true;
}
}
public class MyType
{
[JsonProperty(ItemConverterType = typeof(MyConverter))]
public Dictionary<string, object> MyProperty { get; set; }
}
[Test]
public void DeserializeDictionaryItemConverter()
{
var actual = JsonConvert.DeserializeObject<MyType>(@"{ ""MyProperty"":{""Key"":""Y""}}");
Assert.AreEqual("X", actual.MyProperty["Key"]);
}
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)