-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:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user