-Fixed error when deserializing large JSON integers to XML
-Fixed serializing extension data properties with no setter
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System.Numerics;
|
||||
#if !PORTABLE40
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -1417,6 +1418,11 @@ namespace Newtonsoft.Json.Converters
|
||||
}
|
||||
else if (reader.TokenType == JsonToken.Integer)
|
||||
{
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
if (reader.Value is BigInteger)
|
||||
return ((BigInteger)reader.Value).ToString(CultureInfo.InvariantCulture);
|
||||
#endif
|
||||
|
||||
return XmlConvert.ToString(Convert.ToInt64(reader.Value, CultureInfo.InvariantCulture));
|
||||
}
|
||||
else if (reader.TokenType == JsonToken.Float)
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Newtonsoft.Json.Schema;
|
||||
#if !(NET35 || NET20 || PORTABLE || PORTABLE40)
|
||||
using System.Collections.Concurrent;
|
||||
#endif
|
||||
@@ -438,6 +439,9 @@ namespace Newtonsoft.Json.Serialization
|
||||
if (!m.IsDefined(typeof(JsonExtensionDataAttribute), false))
|
||||
return false;
|
||||
|
||||
if (!ReflectionUtils.CanReadMemberValue(m, true))
|
||||
throw new JsonException("Invalid extension data attribute on '{0}'. Member '{1}' must have a getter.".FormatWith(CultureInfo.InvariantCulture, GetClrTypeFullName(m.DeclaringType), m.Name));
|
||||
|
||||
Type t = ReflectionUtils.GetMemberUnderlyingType(m);
|
||||
|
||||
Type dictionaryType;
|
||||
@@ -479,10 +483,12 @@ namespace Newtonsoft.Json.Serialization
|
||||
else
|
||||
createdType = t;
|
||||
|
||||
MethodInfo addMethod = t.GetMethod("Add", new[] { keyType, valueType });
|
||||
Func<object, object> getExtensionDataDictionary = JsonTypeReflector.ReflectionDelegateFactory.CreateGet<object>(member);
|
||||
Action<object, object> setExtensionDataDictionary = JsonTypeReflector.ReflectionDelegateFactory.CreateSet<object>(member);
|
||||
Action<object, object> setExtensionDataDictionary = (ReflectionUtils.CanSetMemberValue(member, true, false))
|
||||
? JsonTypeReflector.ReflectionDelegateFactory.CreateSet<object>(member)
|
||||
: null;
|
||||
Func<object> createExtensionDataDictionary = JsonTypeReflector.ReflectionDelegateFactory.CreateDefaultConstructor<object>(createdType);
|
||||
MethodInfo addMethod = t.GetMethod("Add", new[] { keyType, valueType });
|
||||
MethodCall<object, object> setExtensionDataDictionaryValue = JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall<object>(addMethod);
|
||||
|
||||
ExtensionDataSetter extensionDataSetter = (o, key, value) =>
|
||||
@@ -490,6 +496,9 @@ namespace Newtonsoft.Json.Serialization
|
||||
object dictionary = getExtensionDataDictionary(o);
|
||||
if (dictionary == null)
|
||||
{
|
||||
if (setExtensionDataDictionary == null)
|
||||
throw new JsonSerializationException("Cannot set value onto extension data member '{0}'. The extension data collection is null and it cannot be set.".FormatWith(CultureInfo.InvariantCulture, member.Name));
|
||||
|
||||
dictionary = createExtensionDataDictionary();
|
||||
setExtensionDataDictionary(o, dictionary);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user