-Performance
This commit is contained in:
@@ -140,19 +140,19 @@ namespace Newtonsoft.Json.Tests
|
||||
[Test]
|
||||
public void Deserialize()
|
||||
{
|
||||
BenchmarkDeserializeMethod<TestClass>(SerializeMethod.DataContractSerializer, XmlText);
|
||||
BenchmarkDeserializeMethod<TestClass>(SerializeMethod.BinaryFormatter, MiscellaneousUtils.HexToBytes(BinaryFormatterHex));
|
||||
//BenchmarkDeserializeMethod<TestClass>(SerializeMethod.DataContractSerializer, XmlText);
|
||||
//BenchmarkDeserializeMethod<TestClass>(SerializeMethod.BinaryFormatter, MiscellaneousUtils.HexToBytes(BinaryFormatterHex));
|
||||
DeserializeTests<TestClass>(JsonText);
|
||||
BenchmarkDeserializeMethod<TestClass>(SerializeMethod.JsonNetWithIsoConverter, JsonIsoText);
|
||||
BenchmarkDeserializeMethod<TestClass>(SerializeMethod.JsonNetBinary, MiscellaneousUtils.HexToBytes(BsonHex));
|
||||
//BenchmarkDeserializeMethod<TestClass>(SerializeMethod.JsonNetWithIsoConverter, JsonIsoText);
|
||||
//BenchmarkDeserializeMethod<TestClass>(SerializeMethod.JsonNetBinary, MiscellaneousUtils.HexToBytes(BsonHex));
|
||||
}
|
||||
|
||||
public void DeserializeTests<T>(string json)
|
||||
{
|
||||
BenchmarkDeserializeMethod<T>(SerializeMethod.JavaScriptSerializer, json);
|
||||
BenchmarkDeserializeMethod<T>(SerializeMethod.DataContractJsonSerializer, json);
|
||||
//BenchmarkDeserializeMethod<T>(SerializeMethod.JavaScriptSerializer, json);
|
||||
//BenchmarkDeserializeMethod<T>(SerializeMethod.DataContractJsonSerializer, json);
|
||||
BenchmarkDeserializeMethod<T>(SerializeMethod.JsonNet, json);
|
||||
BenchmarkDeserializeMethod<T>(SerializeMethod.JsonNetManual, json);
|
||||
//BenchmarkDeserializeMethod<T>(SerializeMethod.JsonNetManual, json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -729,9 +729,9 @@ If attributes are not mentioned, default values are used in each case.
|
||||
Type type = typeof (T);
|
||||
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
serializer.ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace;
|
||||
serializer.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore;
|
||||
serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||
//serializer.ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace;
|
||||
//serializer.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore;
|
||||
//serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||
if (isoDateTimeConverter)
|
||||
serializer.Converters.Add(new IsoDateTimeConverter());
|
||||
|
||||
|
||||
@@ -65,7 +65,6 @@ namespace Newtonsoft.Json.Serialization
|
||||
|
||||
internal bool ShouldCreateWrapper { get; private set; }
|
||||
internal bool CanDeserialize { get; private set; }
|
||||
internal bool IsReadOnlyOrFixedSize { get; private set; }
|
||||
internal ConstructorInfo ParametrizedConstructor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -73,6 +73,7 @@ namespace Newtonsoft.Json.Serialization
|
||||
internal Type NonNullableUnderlyingType;
|
||||
internal ReadType InternalReadType;
|
||||
internal JsonContractType ContractType;
|
||||
internal bool IsReadOnlyOrFixedSize;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying type for the contract.
|
||||
|
||||
@@ -68,7 +68,6 @@ namespace Newtonsoft.Json.Serialization
|
||||
private Func<object> _genericTemporaryDictionaryCreator;
|
||||
|
||||
internal bool ShouldCreateWrapper { get; private set; }
|
||||
internal bool IsReadOnlyOrFixedSize { get; private set; }
|
||||
internal ConstructorInfo ParametrizedConstructor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace Newtonsoft.Json.Serialization
|
||||
ContractType = JsonContractType.Primitive;
|
||||
|
||||
TypeCode = ConvertUtils.GetTypeCode(underlyingType);
|
||||
IsReadOnlyOrFixedSize = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -686,11 +686,11 @@ To fix this error either change the JSON to a {1} or change the deserialized typ
|
||||
// attempt to convert value's type to target's type
|
||||
if (valueType != targetType)
|
||||
{
|
||||
if (value == null && contract.IsNullable)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
if (value == null && contract.IsNullable)
|
||||
return null;
|
||||
|
||||
if (contract.IsConvertable)
|
||||
{
|
||||
JsonPrimitiveContract primitiveContract = (JsonPrimitiveContract)contract;
|
||||
@@ -778,20 +778,20 @@ To fix this error either change the JSON to a {1} or change the deserialized typ
|
||||
return true;
|
||||
}
|
||||
|
||||
if (property.PropertyContract == null)
|
||||
property.PropertyContract = GetContractSafe(property.PropertyType);
|
||||
|
||||
ObjectCreationHandling objectCreationHandling =
|
||||
property.ObjectCreationHandling.GetValueOrDefault(Serializer.ObjectCreationHandling);
|
||||
|
||||
if ((objectCreationHandling == ObjectCreationHandling.Auto || objectCreationHandling == ObjectCreationHandling.Reuse)
|
||||
if ((objectCreationHandling != ObjectCreationHandling.Replace)
|
||||
&& (reader.TokenType == JsonToken.StartArray || reader.TokenType == JsonToken.StartObject)
|
||||
&& property.Readable)
|
||||
{
|
||||
currentValue = property.ValueProvider.GetValue(target);
|
||||
gottenCurrentValue = true;
|
||||
|
||||
useExistingValue = (currentValue != null
|
||||
&& !property.PropertyType.IsArray
|
||||
&& !ReflectionUtils.InheritsGenericDefinition(property.PropertyType, typeof (ReadOnlyCollection<>))
|
||||
&& !property.PropertyType.IsValueType());
|
||||
useExistingValue = (currentValue != null && !property.PropertyContract.IsReadOnlyOrFixedSize && !property.PropertyType.IsValueType());
|
||||
}
|
||||
|
||||
if (!property.Writable && !useExistingValue)
|
||||
@@ -816,9 +816,6 @@ To fix this error either change the JSON to a {1} or change the deserialized typ
|
||||
return true;
|
||||
}
|
||||
|
||||
if (property.PropertyContract == null)
|
||||
property.PropertyContract = GetContractSafe(property.PropertyType);
|
||||
|
||||
if (currentValue == null)
|
||||
{
|
||||
propertyContract = property.PropertyContract;
|
||||
|
||||
@@ -85,8 +85,9 @@ namespace Newtonsoft.Json.Serialization
|
||||
|
||||
private void SerializePrimitive(JsonWriter writer, object value, JsonPrimitiveContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
|
||||
{
|
||||
if (contract.UnderlyingType == typeof (byte[]))
|
||||
if (contract.TypeCode == PrimitiveTypeCode.Bytes)
|
||||
{
|
||||
// if type name handling is enabled then wrap the base64 byte string in an object with the type name
|
||||
bool includeTypeDetails = ShouldWriteType(TypeNameHandling.Objects, contract, member, containerContract, containerProperty);
|
||||
if (includeTypeDetails)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user