-Fixed TypeNameHandling.Auto with some JsonConverters

-Fixed TypeNameHandling.Auto with JsonSerializer.Serialize inside a JsonConverter
-Changed assembly version to 6.0.0.0
-Marked async methods on JsonConverter as obsolete
This commit is contained in:
James Newton-King
2014-01-29 00:47:01 +13:00
parent c4da9cfb17
commit 4793c7b5da
10 changed files with 87 additions and 15 deletions
@@ -7341,7 +7341,7 @@ Parameter name: value",
JsonSerializer serializer = new JsonSerializer();
MultipleItemsClass foo = serializer.Deserialize<MultipleItemsClass>(reader);
values.Add(foo);
}
@@ -8775,7 +8775,7 @@ Parameter name: value",
ExtensionDataDeserializeWithNonDefaultConstructor c = new ExtensionDataDeserializeWithNonDefaultConstructor("Name!");
c._extensionData = new Dictionary<string, JToken>
{
{"Key!", "Value!"}
{ "Key!", "Value!" }
};
string json = JsonConvert.SerializeObject(c, Formatting.Indented);
@@ -54,6 +54,61 @@ namespace Newtonsoft.Json.Tests.Serialization
[TestFixture]
public class TypeNameHandlingTests : TestFixtureBase
{
[Test]
public void DictionaryAuto()
{
Dictionary<string, object> dic = new Dictionary<string, object>
{
{ "movie", new Movie { Name = "Die Hard"}}
};
string json = JsonConvert.SerializeObject(dic, Formatting.Indented, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto
});
Assert.AreEqual(@"{
""movie"": {
""$type"": ""Newtonsoft.Json.Tests.TestObjects.Movie, Newtonsoft.Json.Tests"",
""Name"": ""Die Hard"",
""Description"": null,
""Classification"": null,
""Studio"": null,
""ReleaseDate"": null,
""ReleaseCountries"": null
}
}", json);
}
[Test]
public void KeyValuePairAuto()
{
IList<KeyValuePair<string, object>> dic = new List<KeyValuePair<string, object>>
{
new KeyValuePair<string, object>("movie", new Movie { Name = "Die Hard"})
};
string json = JsonConvert.SerializeObject(dic, Formatting.Indented, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto
});
Assert.AreEqual(@"[
{
""Key"": ""movie"",
""Value"": {
""$type"": ""Newtonsoft.Json.Tests.TestObjects.Movie, Newtonsoft.Json.Tests"",
""Name"": ""Die Hard"",
""Description"": null,
""Classification"": null,
""Studio"": null,
""ReleaseDate"": null,
""ReleaseCountries"": null
}
}
]", json);
}
[Test]
public void NestedValueObjects()
{
@@ -143,7 +143,7 @@ namespace Newtonsoft.Json.Tests.Serialization
#else
[JsonIgnore]
#endif
public string nonSerializedField;
public string nonSerializedField;
public bool Equals(SerializableType other)
{