From a7d47558d8ad5492a6c11152330890ee7cc46e28 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sun, 28 Apr 2013 12:27:47 +1200 Subject: [PATCH] -Added default serializer settings --- Src/Newtonsoft.Json.Tests/JsonConvertTest.cs | 160 ++++++++++++++++ .../Properties/AssemblyInfo.cs | 2 +- Src/Newtonsoft.Json.Tests/TestFixtureBase.cs | 5 +- Src/Newtonsoft.Json/JsonConvert.cs | 16 +- Src/Newtonsoft.Json/JsonSerializer.cs | 175 +++++++++++++----- Src/Newtonsoft.Json/JsonSerializerSettings.cs | 81 ++++++-- Src/Newtonsoft.Json/Linq/JArray.cs | 2 +- Src/Newtonsoft.Json/Linq/JObject.cs | 2 +- Src/Newtonsoft.Json/Linq/JToken.cs | 9 +- Src/Newtonsoft.Json/Linq/JValue.cs | 2 +- .../Properties/AssemblyInfo.cs | 2 +- 11 files changed, 374 insertions(+), 82 deletions(-) diff --git a/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs b/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs index e5255075..1794d5f6 100644 --- a/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs @@ -50,6 +50,166 @@ namespace Newtonsoft.Json.Tests [TestFixture] public class JsonConvertTest : TestFixtureBase { + [Test] + public void DefaultSettings() + { + JsonConvert.DefaultSettings = () => new JsonSerializerSettings + { + Formatting = Formatting.Indented + }; + + string json = JsonConvert.SerializeObject(new { test = new[] { 1, 2, 3 } }); + + Assert.AreEqual(@"{ + ""test"": [ + 1, + 2, + 3 + ] +}", json); + } + + [Test] + public void DefaultSettings_Override() + { + JsonConvert.DefaultSettings = () => new JsonSerializerSettings + { + Formatting = Formatting.Indented + }; + + string json = JsonConvert.SerializeObject(new { test = new[] { 1, 2, 3 } }, new JsonSerializerSettings + { + Formatting = Formatting.None + }); + + Assert.AreEqual(@"{""test"":[1,2,3]}", json); + } + + [Test] + public void DefaultSettings_Override_JsonConverterOrder() + { + JsonConvert.DefaultSettings = () => new JsonSerializerSettings + { + Formatting = Formatting.Indented, + Converters = { new IsoDateTimeConverter { DateTimeFormat = "yyyy" } } + }; + + string json = JsonConvert.SerializeObject(new[] { new DateTime(2000, 12, 12, 4, 2, 4, DateTimeKind.Utc) }, new JsonSerializerSettings + { + Formatting = Formatting.None, + Converters = + { + // should take precedence + new JavaScriptDateTimeConverter(), + new IsoDateTimeConverter { DateTimeFormat = "dd" } + } + }); + + Assert.AreEqual(@"[new Date(976593724000)]", json); + } + + [Test] + public void DefaultSettings_Create() + { + JsonConvert.DefaultSettings = () => new JsonSerializerSettings + { + Formatting = Formatting.Indented + }; + + IList l = new List { 1, 2, 3 }; + + StringWriter sw = new StringWriter(); + JsonSerializer serializer = JsonSerializer.CreateDefault(); + serializer.Serialize(sw, l); + + Assert.AreEqual(@"[ + 1, + 2, + 3 +]", sw.ToString()); + + sw = new StringWriter(); + serializer.Formatting = Formatting.None; + serializer.Serialize(sw, l); + + Assert.AreEqual(@"[1,2,3]", sw.ToString()); + + sw = new StringWriter(); + serializer = new JsonSerializer(); + serializer.Serialize(sw, l); + + Assert.AreEqual(@"[1,2,3]", sw.ToString()); + + sw = new StringWriter(); + serializer = JsonSerializer.Create(); + serializer.Serialize(sw, l); + + Assert.AreEqual(@"[1,2,3]", sw.ToString()); + } + + [Test] + public void DefaultSettings_CreateWithSettings() + { + JsonConvert.DefaultSettings = () => new JsonSerializerSettings + { + Formatting = Formatting.Indented + }; + + IList l = new List { 1, 2, 3 }; + + StringWriter sw = new StringWriter(); + JsonSerializer serializer = JsonSerializer.CreateDefault(new JsonSerializerSettings + { + Converters = { new IntConverter() } + }); + serializer.Serialize(sw, l); + + Assert.AreEqual(@"[ + 2, + 4, + 6 +]", sw.ToString()); + + sw = new StringWriter(); + serializer.Converters.Clear(); + serializer.Serialize(sw, l); + + Assert.AreEqual(@"[ + 1, + 2, + 3 +]", sw.ToString()); + + sw = new StringWriter(); + serializer = JsonSerializer.Create(new JsonSerializerSettings { Formatting = Formatting.Indented }); + serializer.Serialize(sw, l); + + Assert.AreEqual(@"[ + 1, + 2, + 3 +]", sw.ToString()); + } + + public class IntConverter : JsonConverter + { + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + int i = (int)value; + writer.WriteValue(i * 2); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + throw new NotImplementedException(); + } + + public override bool CanConvert(Type objectType) + { + return objectType == typeof(int); + } + } + [Test] public void DeserializeObject_EmptyString() { diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs index 209936a1..9d785d08 100644 --- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs @@ -75,4 +75,4 @@ using System.Security; // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: [assembly: AssemblyVersion("4.5.0.0")] -[assembly: AssemblyFileVersion("5.0.4.16025")] +[assembly: AssemblyFileVersion("5.0.4.16028")] diff --git a/Src/Newtonsoft.Json.Tests/TestFixtureBase.cs b/Src/Newtonsoft.Json.Tests/TestFixtureBase.cs index 802853cf..3c60c72f 100644 --- a/Src/Newtonsoft.Json.Tests/TestFixtureBase.cs +++ b/Src/Newtonsoft.Json.Tests/TestFixtureBase.cs @@ -41,6 +41,7 @@ using NUnit.Framework; using Microsoft.VisualStudio.TestPlatform.UnitTestFramework; using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute; using TestMethod = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute; +using Setup = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestInitialize; #endif using Newtonsoft.Json.Utilities; using System.Collections; @@ -117,13 +118,14 @@ namespace Newtonsoft.Json.Tests return bytes; } -#if !NETFX_CORE [SetUp] protected void TestSetup() { //CultureInfo turkey = CultureInfo.CreateSpecificCulture("tr"); //Thread.CurrentThread.CurrentCulture = turkey; //Thread.CurrentThread.CurrentUICulture = turkey; + + JsonConvert.DefaultSettings = null; } protected void WriteEscapedJson(string json) @@ -135,7 +137,6 @@ namespace Newtonsoft.Json.Tests { return @"@""" + json.Replace(@"""", @"""""") + @""""; } -#endif } #if NETFX_CORE diff --git a/Src/Newtonsoft.Json/JsonConvert.cs b/Src/Newtonsoft.Json/JsonConvert.cs index c86240d4..8055660e 100644 --- a/Src/Newtonsoft.Json/JsonConvert.cs +++ b/Src/Newtonsoft.Json/JsonConvert.cs @@ -36,6 +36,7 @@ using Newtonsoft.Json.Linq; using Newtonsoft.Json.Utilities; using System.Xml; using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Serialization; using System.Text; #if !NET20 && (!SILVERLIGHT || WINDOWS_PHONE) && !PORTABLE40 using System.Xml.Linq; @@ -51,6 +52,15 @@ namespace Newtonsoft.Json /// public static class JsonConvert { + /// + /// Gets or sets a function that creates default . + /// Default settings are automatically used by serialization methods on , + /// and and on . + /// To serialize without using any default settings create a with + /// . + /// + public static Func DefaultSettings { get; set; } + /// /// Represents JavaScript's boolean value true as a string. This field is read-only. /// @@ -595,7 +605,7 @@ namespace Newtonsoft.Json /// public static string SerializeObject(object value, Type type, Formatting formatting, JsonSerializerSettings settings) { - JsonSerializer jsonSerializer = JsonSerializer.Create(settings); + JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(settings); StringBuilder sb = new StringBuilder(256); StringWriter sw = new StringWriter(sb, CultureInfo.InvariantCulture); @@ -793,7 +803,7 @@ namespace Newtonsoft.Json ValidationUtils.ArgumentNotNull(value, "value"); StringReader sr = new StringReader(value); - JsonSerializer jsonSerializer = JsonSerializer.Create(settings); + JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(settings); // by default DeserializeObject should check for additional content if (!jsonSerializer.IsCheckAdditionalContentSet()) @@ -886,7 +896,7 @@ namespace Newtonsoft.Json public static void PopulateObject(string value, object target, JsonSerializerSettings settings) { StringReader sr = new StringReader(value); - JsonSerializer jsonSerializer = JsonSerializer.Create(settings); + JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(settings); using (JsonReader jsonReader = new JsonTextReader(sr)) { diff --git a/Src/Newtonsoft.Json/JsonSerializer.cs b/Src/Newtonsoft.Json/JsonSerializer.cs index ca65b01d..9be8acdf 100644 --- a/Src/Newtonsoft.Json/JsonSerializer.cs +++ b/Src/Newtonsoft.Json/JsonSerializer.cs @@ -442,62 +442,147 @@ namespace Newtonsoft.Json _contractResolver = DefaultContractResolver.Instance; } + /// + /// Creates a new instance. + /// The will not use default settings. + /// + /// + /// A new instance. + /// The will not use default settings. + /// + public static JsonSerializer Create() + { + return new JsonSerializer(); + } + /// /// Creates a new instance using the specified . + /// The will not use default settings. /// /// The settings to be applied to the . - /// A new instance using the specified . + /// + /// A new instance using the specified . + /// The will not use default settings. + /// public static JsonSerializer Create(JsonSerializerSettings settings) { - JsonSerializer jsonSerializer = new JsonSerializer(); + JsonSerializer serializer = Create(); if (settings != null) + ApplySerializerSettings(serializer, settings); + + return serializer; + } + + /// + /// Creates a new instance. + /// The will use default settings. + /// + /// + /// A new instance. + /// The will use default settings. + /// + public static JsonSerializer CreateDefault() + { + Func defaultSettingsCreator = JsonConvert.DefaultSettings; + JsonSerializerSettings defaultSettings = (defaultSettingsCreator != null) ? defaultSettingsCreator() : null; + + return Create(defaultSettings); + } + + /// + /// Creates a new instance using the specified . + /// The will use default settings. + /// + /// The settings to be applied to the . + /// + /// A new instance using the specified . + /// The will use default settings. + /// + public static JsonSerializer CreateDefault(JsonSerializerSettings settings) + { + JsonSerializer serializer = CreateDefault(); + if (settings != null) + ApplySerializerSettings(serializer, settings); + + return serializer; + } + + private static void ApplySerializerSettings(JsonSerializer serializer, JsonSerializerSettings settings) + { + if (!CollectionUtils.IsNullOrEmpty(settings.Converters)) { - if (!CollectionUtils.IsNullOrEmpty(settings.Converters)) - jsonSerializer.Converters.AddRange(settings.Converters); - - // serializer specific - jsonSerializer.TypeNameHandling = settings.TypeNameHandling; - jsonSerializer.TypeNameAssemblyFormat = settings.TypeNameAssemblyFormat; - jsonSerializer.PreserveReferencesHandling = settings.PreserveReferencesHandling; - jsonSerializer.ReferenceLoopHandling = settings.ReferenceLoopHandling; - jsonSerializer.MissingMemberHandling = settings.MissingMemberHandling; - jsonSerializer.ObjectCreationHandling = settings.ObjectCreationHandling; - jsonSerializer.NullValueHandling = settings.NullValueHandling; - jsonSerializer.DefaultValueHandling = settings.DefaultValueHandling; - jsonSerializer.ConstructorHandling = settings.ConstructorHandling; - jsonSerializer.Context = settings.Context; - jsonSerializer._checkAdditionalContent = settings._checkAdditionalContent; - - // reader/writer specific - // unset values won't override reader/writer set values - jsonSerializer._formatting = settings._formatting; - jsonSerializer._dateFormatHandling = settings._dateFormatHandling; - jsonSerializer._dateTimeZoneHandling = settings._dateTimeZoneHandling; - jsonSerializer._dateParseHandling = settings._dateParseHandling; - jsonSerializer._dateFormatString = settings._dateFormatString; - jsonSerializer._dateFormatStringSet = settings._dateFormatStringSet; - jsonSerializer._floatFormatHandling = settings._floatFormatHandling; - jsonSerializer._floatParseHandling = settings._floatParseHandling; - jsonSerializer._stringEscapeHandling = settings._stringEscapeHandling; - jsonSerializer._culture = settings._culture; - jsonSerializer._maxDepth = settings._maxDepth; - jsonSerializer._maxDepthSet = settings._maxDepthSet; - - if (settings.Error != null) - jsonSerializer.Error += settings.Error; - - if (settings.ContractResolver != null) - jsonSerializer.ContractResolver = settings.ContractResolver; - if (settings.ReferenceResolver != null) - jsonSerializer.ReferenceResolver = settings.ReferenceResolver; - if (settings.TraceWriter != null) - jsonSerializer.TraceWriter = settings.TraceWriter; - if (settings.Binder != null) - jsonSerializer.Binder = settings.Binder; + // insert settings converters at the beginning so they take precedence + for (int i = 0; i < settings.Converters.Count; i++) + { + serializer.Converters.Insert(i, settings.Converters[i]); + } } - return jsonSerializer; + // serializer specific + if (settings._typeNameHandling != null) + serializer.TypeNameHandling = settings.TypeNameHandling; + if (settings._typeNameAssemblyFormat != null) + serializer.TypeNameAssemblyFormat = settings.TypeNameAssemblyFormat; + if (settings._preserveReferencesHandling != null) + serializer.PreserveReferencesHandling = settings.PreserveReferencesHandling; + if (settings._referenceLoopHandling != null) + serializer.ReferenceLoopHandling = settings.ReferenceLoopHandling; + if (settings._missingMemberHandling != null) + serializer.MissingMemberHandling = settings.MissingMemberHandling; + if (settings._objectCreationHandling != null) + serializer.ObjectCreationHandling = settings.ObjectCreationHandling; + if (settings._nullValueHandling != null) + serializer.NullValueHandling = settings.NullValueHandling; + if (settings._defaultValueHandling != null) + serializer.DefaultValueHandling = settings.DefaultValueHandling; + if (settings._constructorHandling != null) + serializer.ConstructorHandling = settings.ConstructorHandling; + if (settings._context != null) + serializer.Context = settings.Context; + if (settings._checkAdditionalContent != null) + serializer._checkAdditionalContent = settings._checkAdditionalContent; + + if (settings.Error != null) + serializer.Error += settings.Error; + + if (settings.ContractResolver != null) + serializer.ContractResolver = settings.ContractResolver; + if (settings.ReferenceResolver != null) + serializer.ReferenceResolver = settings.ReferenceResolver; + if (settings.TraceWriter != null) + serializer.TraceWriter = settings.TraceWriter; + if (settings.Binder != null) + serializer.Binder = settings.Binder; + + // reader/writer specific + // unset values won't override reader/writer set values + if (settings._formatting != null) + serializer._formatting = settings._formatting; + if (settings._dateFormatHandling != null) + serializer._dateFormatHandling = settings._dateFormatHandling; + if (settings._dateTimeZoneHandling != null) + serializer._dateTimeZoneHandling = settings._dateTimeZoneHandling; + if (settings._dateParseHandling != null) + serializer._dateParseHandling = settings._dateParseHandling; + if (settings._dateFormatStringSet) + { + serializer._dateFormatString = settings._dateFormatString; + serializer._dateFormatStringSet = settings._dateFormatStringSet; + } + if (settings._floatFormatHandling != null) + serializer._floatFormatHandling = settings._floatFormatHandling; + if (settings._floatParseHandling != null) + serializer._floatParseHandling = settings._floatParseHandling; + if (settings._stringEscapeHandling != null) + serializer._stringEscapeHandling = settings._stringEscapeHandling; + if (settings._culture != null) + serializer._culture = settings._culture; + if (settings._maxDepthSet) + { + serializer._maxDepth = settings._maxDepth; + serializer._maxDepthSet = settings._maxDepthSet; + } } /// diff --git a/Src/Newtonsoft.Json/JsonSerializerSettings.cs b/Src/Newtonsoft.Json/JsonSerializerSettings.cs index 80307643..e2c19849 100644 --- a/Src/Newtonsoft.Json/JsonSerializerSettings.cs +++ b/Src/Newtonsoft.Json/JsonSerializerSettings.cs @@ -55,6 +55,7 @@ namespace Newtonsoft.Json internal const FloatParseHandling DefaultFloatParseHandling = FloatParseHandling.Double; internal const FloatFormatHandling DefaultFloatFormatHandling = FloatFormatHandling.String; internal const StringEscapeHandling DefaultStringEscapeHandling = StringEscapeHandling.Default; + internal const FormatterAssemblyStyle DefaultFormatterAssemblyStyle = FormatterAssemblyStyle.Simple; internal static readonly CultureInfo DefaultCulture; internal const bool DefaultCheckAdditionalContent = false; internal const string DefaultDateFormatString = @"yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK"; @@ -72,36 +73,66 @@ namespace Newtonsoft.Json internal bool _maxDepthSet; internal string _dateFormatString; internal bool _dateFormatStringSet; + internal FormatterAssemblyStyle? _typeNameAssemblyFormat; + internal DefaultValueHandling? _defaultValueHandling; + internal PreserveReferencesHandling? _preserveReferencesHandling; + internal NullValueHandling? _nullValueHandling; + internal ObjectCreationHandling? _objectCreationHandling; + internal MissingMemberHandling? _missingMemberHandling; + internal ReferenceLoopHandling? _referenceLoopHandling; + internal StreamingContext? _context; + internal ConstructorHandling? _constructorHandling; + internal TypeNameHandling? _typeNameHandling; /// /// Gets or sets how reference loops (e.g. a class referencing itself) is handled. /// /// Reference loop handling. - public ReferenceLoopHandling ReferenceLoopHandling { get; set; } + public ReferenceLoopHandling ReferenceLoopHandling + { + get { return _referenceLoopHandling ?? DefaultReferenceLoopHandling; } + set { _referenceLoopHandling = value; } + } /// /// Gets or sets how missing members (e.g. JSON contains a property that isn't a member on the object) are handled during deserialization. /// /// Missing member handling. - public MissingMemberHandling MissingMemberHandling { get; set; } + public MissingMemberHandling MissingMemberHandling + { + get { return _missingMemberHandling ?? DefaultMissingMemberHandling; } + set { _missingMemberHandling = value; } + } /// /// Gets or sets how objects are created during deserialization. /// /// The object creation handling. - public ObjectCreationHandling ObjectCreationHandling { get; set; } + public ObjectCreationHandling ObjectCreationHandling + { + get { return _objectCreationHandling ?? DefaultObjectCreationHandling; } + set { _objectCreationHandling = value; } + } /// /// Gets or sets how null values are handled during serialization and deserialization. /// /// Null value handling. - public NullValueHandling NullValueHandling { get; set; } + public NullValueHandling NullValueHandling + { + get { return _nullValueHandling ?? DefaultNullValueHandling; } + set { _nullValueHandling = value; } + } /// /// Gets or sets how null default are handled during serialization and deserialization. /// /// The default value handling. - public DefaultValueHandling DefaultValueHandling { get; set; } + public DefaultValueHandling DefaultValueHandling + { + get { return _defaultValueHandling ?? DefaultDefaultValueHandling; } + set { _defaultValueHandling = value; } + } /// /// Gets or sets a collection that will be used during serialization. @@ -113,25 +144,41 @@ namespace Newtonsoft.Json /// Gets or sets how object references are preserved by the serializer. /// /// The preserve references handling. - public PreserveReferencesHandling PreserveReferencesHandling { get; set; } + public PreserveReferencesHandling PreserveReferencesHandling + { + get { return _preserveReferencesHandling ?? DefaultPreserveReferencesHandling; } + set { _preserveReferencesHandling = value; } + } /// /// Gets or sets how type name writing and reading is handled by the serializer. /// /// The type name handling. - public TypeNameHandling TypeNameHandling { get; set; } + public TypeNameHandling TypeNameHandling + { + get { return _typeNameHandling ?? DefaultTypeNameHandling; } + set { _typeNameHandling = value; } + } /// /// Gets or sets how a type name assembly is written and resolved by the serializer. /// /// The type name assembly format. - public FormatterAssemblyStyle TypeNameAssemblyFormat { get; set; } + public FormatterAssemblyStyle TypeNameAssemblyFormat + { + get { return _typeNameAssemblyFormat ?? DefaultFormatterAssemblyStyle; } + set { _typeNameAssemblyFormat = value; } + } /// /// Gets or sets how constructors are used during deserialization. /// /// The constructor handling. - public ConstructorHandling ConstructorHandling { get; set; } + public ConstructorHandling ConstructorHandling + { + get { return _constructorHandling ?? DefaultConstructorHandling; } + set { _constructorHandling = value; } + } /// /// Gets or sets the contract resolver used by the serializer when @@ -168,7 +215,11 @@ namespace Newtonsoft.Json /// Gets or sets the used by the serializer when invoking serialization callback methods. /// /// The context. - public StreamingContext Context { get; set; } + public StreamingContext Context + { + get { return _context ?? DefaultContext; } + set { _context = value; } + } /// /// Get or set how and values are formatting when writing JSON text. @@ -296,16 +347,6 @@ namespace Newtonsoft.Json /// public JsonSerializerSettings() { - ReferenceLoopHandling = DefaultReferenceLoopHandling; - MissingMemberHandling = DefaultMissingMemberHandling; - ObjectCreationHandling = DefaultObjectCreationHandling; - NullValueHandling = DefaultNullValueHandling; - DefaultValueHandling = DefaultDefaultValueHandling; - PreserveReferencesHandling = DefaultPreserveReferencesHandling; - TypeNameHandling = DefaultTypeNameHandling; - TypeNameAssemblyFormat = DefaultTypeNameAssemblyFormat; - Context = DefaultContext; - Converters = new List(); } } diff --git a/Src/Newtonsoft.Json/Linq/JArray.cs b/Src/Newtonsoft.Json/Linq/JArray.cs index e8617d50..76adf1a2 100644 --- a/Src/Newtonsoft.Json/Linq/JArray.cs +++ b/Src/Newtonsoft.Json/Linq/JArray.cs @@ -160,7 +160,7 @@ namespace Newtonsoft.Json.Linq /// A with the values of the specified object public static new JArray FromObject(object o) { - return FromObject(o, new JsonSerializer()); + return FromObject(o, JsonSerializer.CreateDefault()); } /// diff --git a/Src/Newtonsoft.Json/Linq/JObject.cs b/Src/Newtonsoft.Json/Linq/JObject.cs index 7ba340d5..c22240c6 100644 --- a/Src/Newtonsoft.Json/Linq/JObject.cs +++ b/Src/Newtonsoft.Json/Linq/JObject.cs @@ -342,7 +342,7 @@ namespace Newtonsoft.Json.Linq /// A with the values of the specified object public static new JObject FromObject(object o) { - return FromObject(o, new JsonSerializer()); + return FromObject(o, JsonSerializer.CreateDefault()); } /// diff --git a/Src/Newtonsoft.Json/Linq/JToken.cs b/Src/Newtonsoft.Json/Linq/JToken.cs index df2ad5a6..2e826ac4 100644 --- a/Src/Newtonsoft.Json/Linq/JToken.cs +++ b/Src/Newtonsoft.Json/Linq/JToken.cs @@ -1572,7 +1572,7 @@ namespace Newtonsoft.Json.Linq /// A with the value of the specified object public static JToken FromObject(object o) { - return FromObjectInternal(o, new JsonSerializer()); + return FromObjectInternal(o, JsonSerializer.CreateDefault()); } /// @@ -1602,11 +1602,6 @@ namespace Newtonsoft.Json.Linq /// The object type that the token will be deserialized to. /// The new object created from the JSON value. public object ToObject(Type objectType) - { - return ToObject(objectType, false); - } - - private object ToObject(Type objectType, bool isNullable) { PrimitiveTypeCode typeCode = ConvertUtils.GetTypeCode(objectType); @@ -1694,7 +1689,7 @@ namespace Newtonsoft.Json.Linq #endif } - return ToObject(objectType, new JsonSerializer()); + return ToObject(objectType, JsonSerializer.CreateDefault()); } /// diff --git a/Src/Newtonsoft.Json/Linq/JValue.cs b/Src/Newtonsoft.Json/Linq/JValue.cs index c090a5a8..0867bf8c 100644 --- a/Src/Newtonsoft.Json/Linq/JValue.cs +++ b/Src/Newtonsoft.Json/Linq/JValue.cs @@ -617,7 +617,7 @@ namespace Newtonsoft.Json.Linq JsonConverter matchingConverter = JsonSerializer.GetMatchingConverter(converters, _value.GetType()); if (matchingConverter != null) { - matchingConverter.WriteJson(writer, _value, new JsonSerializer()); + matchingConverter.WriteJson(writer, _value, JsonSerializer.CreateDefault()); return; } } diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs index 6a35f831..05e1ac70 100644 --- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs @@ -92,6 +92,6 @@ using System.Security; // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: [assembly: AssemblyVersion("4.5.0.0")] -[assembly: AssemblyFileVersion("5.0.4.16025")] +[assembly: AssemblyFileVersion("5.0.4.16028")] [assembly: CLSCompliant(true)]