-Added DeserializeAnonymousType overload with JsonSerializerSettings

-Added support for specifying the root type when serialize JSON to use with TypeNameHandling.Auto
-Fixed recursively reading type wrapper objects when deserializing
This commit is contained in:
James Newton-King
2013-02-23 22:09:51 -08:00
parent 159c5ee8cd
commit f9fa0b00e7
10 changed files with 177 additions and 10 deletions
+21 -1
View File
@@ -792,6 +792,16 @@ namespace Newtonsoft.Json
return SerializeObject(value, Formatting.None, settings);
}
public static string SerializeObject<T>(T value, JsonSerializerSettings settings)
{
return SerializeObject<T>(value, Formatting.None, settings);
}
public static string SerializeObject<T>(T value, Formatting formatting, JsonSerializerSettings settings)
{
return SerializeObjectInternal(value, formatting, settings, typeof (T));
}
/// <summary>
/// Serializes the specified object to a JSON string using a collection of <see cref="JsonConverter"/>.
/// </summary>
@@ -803,6 +813,11 @@ namespace Newtonsoft.Json
/// A JSON string representation of the object.
/// </returns>
public static string SerializeObject(object value, Formatting formatting, JsonSerializerSettings settings)
{
return SerializeObjectInternal(value, formatting, settings, null);
}
public static string SerializeObjectInternal(object value, Formatting formatting, JsonSerializerSettings settings, Type rootType)
{
JsonSerializer jsonSerializer = JsonSerializer.Create(settings);
@@ -812,7 +827,7 @@ namespace Newtonsoft.Json
{
jsonWriter.Formatting = formatting;
jsonSerializer.Serialize(jsonWriter, value);
jsonSerializer.Serialize(jsonWriter, value, rootType);
}
return sw.ToString();
@@ -924,6 +939,11 @@ namespace Newtonsoft.Json
return DeserializeObject<T>(value);
}
public static T DeserializeAnonymousType<T>(string value, T anonymousTypeObject, JsonSerializerSettings settings)
{
return DeserializeObject<T>(value, settings);
}
/// <summary>
/// Deserializes the JSON to the specified .NET type.
/// </summary>