-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
@@ -49,6 +49,7 @@ namespace Newtonsoft.Json.Serialization
internal class JsonSerializerInternalWriter : JsonSerializerInternalBase
{
private JsonContract _rootContract;
private int _rootLevel;
private readonly List<object> _serializeStack = new List<object>();
private JsonSerializerProxy _internalSerializer;
@@ -62,14 +63,13 @@ namespace Newtonsoft.Json.Serialization
if (jsonWriter == null)
throw new ArgumentNullException("jsonWriter");
if (objectType != null)
_rootContract = Serializer._contractResolver.ResolveContract(objectType);
_rootContract = (objectType != null) ? Serializer._contractResolver.ResolveContract(objectType) : null;
_rootLevel = _serializeStack.Count + 1;
JsonContract contract = GetContractSafe(value);
try
{
SerializeValue(jsonWriter, value, contract, null, null, null);
}
catch (Exception ex)
@@ -87,6 +87,12 @@ namespace Newtonsoft.Json.Serialization
throw;
}
}
finally
{
// clear root contract to ensure that if level was > 1 then it won't
// accidently be used for non root values
_rootContract = null;
}
}
private JsonSerializerProxy GetInternalSerializer()
@@ -869,7 +875,7 @@ To fix this error either change the environment to be fully trusted, change the
if (containerContract.ItemContract == null || contract.UnderlyingType != containerContract.ItemContract.CreatedType)
return true;
}
else if (_rootContract != null && _serializeStack.Count == 1)
else if (_rootContract != null && _serializeStack.Count == _rootLevel)
{
if (contract.UnderlyingType != _rootContract.CreatedType)
return true;