-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
@@ -46,6 +46,7 @@ namespace Newtonsoft.Json.Serialization
{
internal class JsonSerializerInternalWriter : JsonSerializerInternalBase
{
private JsonContract _rootContract;
private readonly List<object> _serializeStack = new List<object>();
private JsonSerializerProxy _internalSerializer;
@@ -54,11 +55,14 @@ namespace Newtonsoft.Json.Serialization
{
}
public void Serialize(JsonWriter jsonWriter, object value)
public void Serialize(JsonWriter jsonWriter, object value, Type rootType)
{
if (jsonWriter == null)
throw new ArgumentNullException("jsonWriter");
if (rootType != null)
_rootContract = Serializer.ContractResolver.ResolveContract(rootType);
SerializeValue(jsonWriter, value, GetContractSafe(value), null, null, null);
}
@@ -802,6 +806,11 @@ To fix this error either change the environment to be fully trusted, change the
if (contract.UnderlyingType != containerContract.ItemContract.CreatedType)
return true;
}
else if (_rootContract != null && _serializeStack.Count == 1)
{
if (contract.UnderlyingType != _rootContract.CreatedType)
return true;
}
}
return false;