diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/JValueCast.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/JValueCast.cs index f5e63334..442accec 100644 --- a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/JValueCast.cs +++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/JValueCast.cs @@ -41,7 +41,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq Console.WriteLine(u); // http://www.bing.com/ - JValue v6 = new JValue((object)null); + JValue v6 = JValue.CreateNull(); u = (Uri)v6; Console.WriteLine((u != null) ? u.ToString() : "{null}"); diff --git a/Src/Newtonsoft.Json.Tests/Linq/DynamicTests.cs b/Src/Newtonsoft.Json.Tests/Linq/DynamicTests.cs index 1a62c976..6561287a 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/DynamicTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/DynamicTests.cs @@ -167,7 +167,7 @@ namespace Newtonsoft.Json.Tests.Linq public void JValueEquals() { JObject o = new JObject( - new JProperty("Null", new JValue(null, JTokenType.Null)), + new JProperty("Null", JValue.CreateNull()), new JProperty("Integer", new JValue(1)), new JProperty("Float", new JValue(1.1d)), new JProperty("Decimal", new JValue(1.1m)), @@ -187,7 +187,7 @@ namespace Newtonsoft.Json.Tests.Linq Assert.IsTrue(d.Null == d.Null); Assert.IsTrue(d.Null == null); - Assert.IsTrue(d.Null == new JValue(null, JTokenType.Null)); + Assert.IsTrue(d.Null == JValue.CreateNull()); Assert.IsFalse(d.Null == 1); Assert.IsTrue(d.Integer == d.Integer); @@ -276,7 +276,7 @@ namespace Newtonsoft.Json.Tests.Linq public void JValueAddition() { JObject o = new JObject( - new JProperty("Null", new JValue(null, JTokenType.Null)), + new JProperty("Null", JValue.CreateNull()), new JProperty("Integer", new JValue(1)), new JProperty("Float", new JValue(1.1d)), new JProperty("Decimal", new JValue(1.1m)), @@ -611,7 +611,7 @@ namespace Newtonsoft.Json.Tests.Linq public void JValueToString() { JObject o = new JObject( - new JProperty("Null", new JValue(null, JTokenType.Null)), + new JProperty("Null", JValue.CreateNull()), new JProperty("Integer", new JValue(1)), new JProperty("Float", new JValue(1.1)), new JProperty("DateTime", new JValue(new DateTime(2000, 12, 29, 23, 51, 10, DateTimeKind.Utc))), diff --git a/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs index 33df0d4d..00b86889 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs @@ -57,6 +57,7 @@ namespace Newtonsoft.Json.Tests.Linq [TestFixture] public class JObjectTests : TestFixtureBase { +#if !(NET35 || NET20 || PORTABLE40) [Test] public void EmbedJValueStringInNewJObject() { @@ -73,6 +74,7 @@ namespace Newtonsoft.Json.Tests.Linq Assert.AreEqual(null, v.Value); Assert.IsNull((string)o.title); } +#endif [Test] public void JObjectWithComments() @@ -156,7 +158,7 @@ namespace Newtonsoft.Json.Tests.Linq Assert.AreEqual(1, o.Children().Count()); Assert.AreEqual(true, o.TryGetValue("PropertyNameValue", out t)); - Assert.AreEqual(true, JToken.DeepEquals(new JValue((object)null), t)); + Assert.AreEqual(true, JToken.DeepEquals(JValue.CreateNull(), t)); } [Test] @@ -771,7 +773,7 @@ Parameter name: arrayIndex", o["NullValue"] = null; Assert.AreEqual(null, changing); Assert.AreEqual(null, changed); - Assert.AreEqual(new JValue((object)null), o["NullValue"]); + Assert.AreEqual(JValue.CreateNull(), o["NullValue"]); Assert.AreEqual(4, changingCount); Assert.AreEqual(4, changedCount); @@ -815,7 +817,7 @@ Parameter name: arrayIndex", o["NullValue"] = null; Assert.AreEqual(null, changed); - Assert.AreEqual(new JValue((object)null), o["NullValue"]); + Assert.AreEqual(JValue.CreateNull(), o["NullValue"]); Assert.AreEqual(4, changedCount); o["NullValue"] = null; diff --git a/Src/Newtonsoft.Json.Tests/Linq/JPropertyTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JPropertyTests.cs index bed7057a..4d295e79 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JPropertyTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JPropertyTests.cs @@ -144,7 +144,7 @@ namespace Newtonsoft.Json.Tests.Linq property = JProperty.Load(reader); Assert.AreEqual("propertyname", property.Name); - Assert.IsTrue(JToken.DeepEquals(new JValue(null, JTokenType.Null), property.Value)); + Assert.IsTrue(JToken.DeepEquals(JValue.CreateNull(), property.Value)); Assert.AreEqual(JsonToken.EndObject, reader.TokenType); } diff --git a/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs index 24d0a2c7..91319040 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs @@ -247,7 +247,7 @@ namespace Newtonsoft.Json.Tests.Linq Assert.AreEqual(true, (bool)new JValue(true)); Assert.AreEqual(true, (bool?)new JValue(true)); Assert.AreEqual(null, (bool?)((JValue)null)); - Assert.AreEqual(null, (bool?)new JValue((object)null)); + Assert.AreEqual(null, (bool?)JValue.CreateNull()); Assert.AreEqual(10, (long)new JValue(10)); Assert.AreEqual(null, (long?)new JValue((long?)null)); Assert.AreEqual(null, (long?)(JValue)null); @@ -287,13 +287,13 @@ namespace Newtonsoft.Json.Tests.Linq Assert.AreEqual(5f, (float?)(new JValue(5m))); Assert.AreEqual(5, (byte)(new JValue(5))); - Assert.AreEqual(null, (sbyte?)new JValue((object)null)); + Assert.AreEqual(null, (sbyte?)JValue.CreateNull()); Assert.AreEqual("1", (string)(new JValue(1))); Assert.AreEqual("1", (string)(new JValue(1.0))); Assert.AreEqual("1.0", (string)(new JValue(1.0m))); Assert.AreEqual("True", (string)(new JValue(true))); - Assert.AreEqual(null, (string)(new JValue((object)null))); + Assert.AreEqual(null, (string)(JValue.CreateNull())); Assert.AreEqual(null, (string)(JValue)null); Assert.AreEqual("12/12/2000 12:12:12", (string)(new JValue(new DateTime(2000, 12, 12, 12, 12, 12, DateTimeKind.Utc)))); #if !NET20 @@ -320,7 +320,7 @@ namespace Newtonsoft.Json.Tests.Linq Assert.AreEqual(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC"), (Guid)(new JValue(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC")))); Assert.AreEqual(new Uri("http://www.google.com"), (Uri)(new JValue("http://www.google.com"))); Assert.AreEqual(new Uri("http://www.google.com"), (Uri)(new JValue(new Uri("http://www.google.com")))); - Assert.AreEqual(null, (Uri)(new JValue((object)null))); + Assert.AreEqual(null, (Uri)(JValue.CreateNull())); Assert.AreEqual(Convert.ToBase64String(Encoding.UTF8.GetBytes("hi")), (string)(new JValue(Encoding.UTF8.GetBytes("hi")))); CollectionAssert.AreEquivalent((byte[])Encoding.UTF8.GetBytes("hi"), (byte[])(new JValue(Convert.ToBase64String(Encoding.UTF8.GetBytes("hi"))))); Assert.AreEqual(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC"), (Guid)(new JValue(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC").ToByteArray()))); @@ -367,7 +367,7 @@ namespace Newtonsoft.Json.Tests.Linq Assert.AreEqual(new BigInteger(byte.MaxValue), (new JValue(byte.MaxValue)).ToObject()); Assert.AreEqual(new BigInteger(123), (new JValue(123)).ToObject()); Assert.AreEqual(new BigInteger(123), (new JValue(123)).ToObject()); - Assert.AreEqual(null, (new JValue((object)null)).ToObject()); + Assert.AreEqual(null, (JValue.CreateNull()).ToObject()); byte[] intData = BigInteger.Parse(bigIntegerText).ToByteArray(); Assert.AreEqual(BigInteger.Parse(bigIntegerText), (new JValue(intData)).ToObject()); @@ -392,7 +392,7 @@ namespace Newtonsoft.Json.Tests.Linq ExceptionAssert.Throws("Can not convert Float to DateTime.", () => { var i = (DateTime)new JValue(1.1m); }); ExceptionAssert.Throws("Can not convert TimeSpan to DateTime.", () => { var i = (DateTime)new JValue(TimeSpan.Zero); }); ExceptionAssert.Throws("Can not convert Uri to DateTime.", () => { var i = (DateTime)new JValue(new Uri("http://www.google.com")); }); - ExceptionAssert.Throws("Can not convert Null to DateTime.", () => { var i = (DateTime)new JValue((object)null); }); + ExceptionAssert.Throws("Can not convert Null to DateTime.", () => { var i = (DateTime)JValue.CreateNull(); }); ExceptionAssert.Throws("Can not convert Guid to DateTime.", () => { var i = (DateTime)new JValue(Guid.NewGuid()); }); ExceptionAssert.Throws("Can not convert Boolean to Uri.", () => { var i = (Uri)new JValue(true); }); @@ -410,7 +410,7 @@ namespace Newtonsoft.Json.Tests.Linq ExceptionAssert.Throws("Can not convert Integer to TimeSpan.", () => { var i = (TimeSpan)new JValue(1); }); ExceptionAssert.Throws("Can not convert Float to TimeSpan.", () => { var i = (TimeSpan)new JValue(1.1); }); ExceptionAssert.Throws("Can not convert Float to TimeSpan.", () => { var i = (TimeSpan)new JValue(1.1m); }); - ExceptionAssert.Throws("Can not convert Null to TimeSpan.", () => { var i = (TimeSpan)new JValue((object)null); }); + ExceptionAssert.Throws("Can not convert Null to TimeSpan.", () => { var i = (TimeSpan)JValue.CreateNull(); }); ExceptionAssert.Throws("Can not convert Guid to TimeSpan.", () => { var i = (TimeSpan)new JValue(Guid.NewGuid()); }); ExceptionAssert.Throws("Can not convert Date to TimeSpan.", () => { var i = (TimeSpan)new JValue(DateTime.Now); }); #if !NET20 @@ -422,7 +422,7 @@ namespace Newtonsoft.Json.Tests.Linq ExceptionAssert.Throws("Can not convert Integer to Guid.", () => { var i = (Guid)new JValue(1); }); ExceptionAssert.Throws("Can not convert Float to Guid.", () => { var i = (Guid)new JValue(1.1); }); ExceptionAssert.Throws("Can not convert Float to Guid.", () => { var i = (Guid)new JValue(1.1m); }); - ExceptionAssert.Throws("Can not convert Null to Guid.", () => { var i = (Guid)new JValue((object)null); }); + ExceptionAssert.Throws("Can not convert Null to Guid.", () => { var i = (Guid)JValue.CreateNull(); }); ExceptionAssert.Throws("Can not convert Date to Guid.", () => { var i = (Guid)new JValue(DateTime.Now); }); #if !NET20 ExceptionAssert.Throws("Can not convert Date to Guid.", () => { var i = (Guid)new JValue(DateTimeOffset.Now); }); @@ -437,7 +437,7 @@ namespace Newtonsoft.Json.Tests.Linq #if !(NET20 || NET35 || PORTABLE || PORTABLE40) ExceptionAssert.Throws("Can not convert Uri to BigInteger.", () => { var i = (new JValue(new Uri("http://www.google.com"))).ToObject(); }); - ExceptionAssert.Throws("Can not convert Null to BigInteger.", () => { var i = (new JValue((object)null)).ToObject(); }); + ExceptionAssert.Throws("Can not convert Null to BigInteger.", () => { var i = (JValue.CreateNull()).ToObject(); }); ExceptionAssert.Throws("Can not convert Guid to BigInteger.", () => { var i = (new JValue(Guid.NewGuid())).ToObject(); }); ExceptionAssert.Throws("Can not convert Guid to BigInteger.", () => { var i = (new JValue(Guid.NewGuid())).ToObject(); }); #endif @@ -452,7 +452,7 @@ namespace Newtonsoft.Json.Tests.Linq #if !(NET20 || NET35 || PORTABLE) Assert.AreEqual((BigInteger)1, (new JValue(1).ToObject(typeof(BigInteger)))); Assert.AreEqual((BigInteger)1, (new JValue(1).ToObject(typeof(BigInteger?)))); - Assert.AreEqual((BigInteger?)null, (new JValue((object)null).ToObject(typeof(BigInteger?)))); + Assert.AreEqual((BigInteger?)null, (JValue.CreateNull().ToObject(typeof(BigInteger?)))); #endif Assert.AreEqual((ushort)1, (new JValue(1).ToObject(typeof(ushort)))); Assert.AreEqual((ushort)1, (new JValue(1).ToObject(typeof(ushort?)))); @@ -542,10 +542,10 @@ namespace Newtonsoft.Json.Tests.Linq Assert.IsTrue(JToken.DeepEquals(new JValue(decimal.MinValue), (JValue)decimal.MinValue)); Assert.IsTrue(JToken.DeepEquals(new JValue(float.MaxValue), (JValue)(float?)float.MaxValue)); Assert.IsTrue(JToken.DeepEquals(new JValue(double.MaxValue), (JValue)(double?)double.MaxValue)); - Assert.IsTrue(JToken.DeepEquals(new JValue((object)null), (JValue)(double?)null)); + Assert.IsTrue(JToken.DeepEquals(JValue.CreateNull(), (JValue)(double?)null)); Assert.IsFalse(JToken.DeepEquals(new JValue(true), (JValue)(bool?)null)); - Assert.IsFalse(JToken.DeepEquals(new JValue((object)null), (JValue)(object)null)); + Assert.IsFalse(JToken.DeepEquals(JValue.CreateNull(), (JValue)(object)null)); byte[] emptyData = new byte[0]; Assert.IsTrue(JToken.DeepEquals(new JValue(emptyData), (JValue)emptyData)); @@ -553,12 +553,12 @@ namespace Newtonsoft.Json.Tests.Linq Assert.IsTrue(JToken.DeepEquals(new JValue(Encoding.UTF8.GetBytes("Hi")), (JValue)Encoding.UTF8.GetBytes("Hi"))); Assert.IsTrue(JToken.DeepEquals(new JValue(TimeSpan.FromMinutes(1)), (JValue)TimeSpan.FromMinutes(1))); - Assert.IsTrue(JToken.DeepEquals(new JValue((object)null), (JValue)(TimeSpan?)null)); + Assert.IsTrue(JToken.DeepEquals(JValue.CreateNull(), (JValue)(TimeSpan?)null)); Assert.IsTrue(JToken.DeepEquals(new JValue(TimeSpan.FromMinutes(1)), (JValue)(TimeSpan?)TimeSpan.FromMinutes(1))); Assert.IsTrue(JToken.DeepEquals(new JValue(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC")), (JValue)new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC"))); Assert.IsTrue(JToken.DeepEquals(new JValue(new Uri("http://www.google.com")), (JValue)new Uri("http://www.google.com"))); - Assert.IsTrue(JToken.DeepEquals(new JValue((object)null), (JValue)(Uri)null)); - Assert.IsTrue(JToken.DeepEquals(new JValue((object)null), (JValue)(Guid?)null)); + Assert.IsTrue(JToken.DeepEquals(JValue.CreateNull(), (JValue)(Uri)null)); + Assert.IsTrue(JToken.DeepEquals(JValue.CreateNull(), (JValue)(Guid?)null)); } [Test] diff --git a/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs index d7975c89..6e6e1ed6 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs @@ -52,6 +52,19 @@ namespace Newtonsoft.Json.Tests.Linq [TestFixture] public class JValueTests : TestFixtureBase { + + [Test] + public void UndefinedTests() + { + JValue v = JValue.CreateUndefined(); + + Assert.AreEqual(JTokenType.Undefined, v.Type); + Assert.AreEqual(null, v.Value); + + Assert.AreEqual("", v.ToString()); + Assert.AreEqual("undefined", v.ToString(Formatting.None)); + } + [Test] public void FloatParseHandling() { @@ -183,10 +196,10 @@ namespace Newtonsoft.Json.Tests.Linq v = new JValue("I am a string!"); Assert.AreEqual("I am a string!", v.ToString()); - v = new JValue(null, JTokenType.Null); + v = JValue.CreateNull(); Assert.AreEqual("", v.ToString()); - v = new JValue(null, JTokenType.Null); + v = JValue.CreateNull(); Assert.AreEqual("", v.ToString(null, CultureInfo.InvariantCulture)); v = new JValue(new DateTime(2000, 12, 12, 20, 59, 59, DateTimeKind.Utc), JTokenType.Date); @@ -333,7 +346,7 @@ namespace Newtonsoft.Json.Tests.Linq ExceptionAssert.Throws("Can not convert Null to Int32.", () => { - JValue v = new JValue((object)null); + JValue v = JValue.CreateNull(); int i = (int)v; }); } @@ -577,7 +590,7 @@ namespace Newtonsoft.Json.Tests.Linq [Test] public void ConvertsToString_Null() { - Assert.AreEqual(string.Empty, Convert.ToString(new JValue((object)null))); + Assert.AreEqual(string.Empty, Convert.ToString(JValue.CreateNull())); } [Test] diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs index 3720bc87..bacc0854 100644 --- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs @@ -75,4 +75,4 @@ using System.Security; // by using the '*' as shown below: [assembly: AssemblyVersion("6.0.0.0")] -[assembly: AssemblyFileVersion("6.0.3.17227")] +[assembly: AssemblyFileVersion("6.0.3.17229")] diff --git a/Src/Newtonsoft.Json/Linq/JContainer.cs b/Src/Newtonsoft.Json/Linq/JContainer.cs index c161c2d9..c42c5b12 100644 --- a/Src/Newtonsoft.Json/Linq/JContainer.cs +++ b/Src/Newtonsoft.Json/Linq/JContainer.cs @@ -292,7 +292,7 @@ namespace Newtonsoft.Json.Linq internal JToken EnsureParentToken(JToken item, bool skipParentCheck) { if (item == null) - return new JValue((object)null); + return JValue.CreateNull(); if (skipParentCheck) return item; @@ -713,12 +713,12 @@ namespace Newtonsoft.Json.Linq parent.Add(v); break; case JsonToken.Null: - v = new JValue(null, JTokenType.Null); + v = JValue.CreateNull(); v.SetLineInfo(lineInfo); parent.Add(v); break; case JsonToken.Undefined: - v = new JValue(null, JTokenType.Undefined); + v = JValue.CreateUndefined(); v.SetLineInfo(lineInfo); parent.Add(v); break; diff --git a/Src/Newtonsoft.Json/Linq/JProperty.cs b/Src/Newtonsoft.Json/Linq/JProperty.cs index e13f4917..927bb7a4 100644 --- a/Src/Newtonsoft.Json/Linq/JProperty.cs +++ b/Src/Newtonsoft.Json/Linq/JProperty.cs @@ -70,7 +70,7 @@ namespace Newtonsoft.Json.Linq { CheckReentrancy(); - JToken newValue = value ?? new JValue((object)null); + JToken newValue = value ?? JValue.CreateNull(); if (_content.Count == 0) { diff --git a/Src/Newtonsoft.Json/Linq/JToken.cs b/Src/Newtonsoft.Json/Linq/JToken.cs index b946f888..c7691f00 100644 --- a/Src/Newtonsoft.Json/Linq/JToken.cs +++ b/Src/Newtonsoft.Json/Linq/JToken.cs @@ -1861,11 +1861,11 @@ namespace Newtonsoft.Json.Linq v.SetLineInfo(lineInfo); return v; case JsonToken.Null: - v = new JValue(null, JTokenType.Null); + v = JValue.CreateNull(); v.SetLineInfo(lineInfo); return v; case JsonToken.Undefined: - v = new JValue(null, JTokenType.Undefined); + v = JValue.CreateUndefined(); v.SetLineInfo(lineInfo); return v; default: diff --git a/Src/Newtonsoft.Json/Linq/JTokenWriter.cs b/Src/Newtonsoft.Json/Linq/JTokenWriter.cs index ac212c72..ff1fb543 100644 --- a/Src/Newtonsoft.Json/Linq/JTokenWriter.cs +++ b/Src/Newtonsoft.Json/Linq/JTokenWriter.cs @@ -176,7 +176,7 @@ namespace Newtonsoft.Json.Linq } else { - _value = value ?? new JValue((object)null); + _value = value ?? JValue.CreateNull(); } } diff --git a/Src/Newtonsoft.Json/Linq/JValue.cs b/Src/Newtonsoft.Json/Linq/JValue.cs index 15f79fe4..cf6f7d65 100644 --- a/Src/Newtonsoft.Json/Linq/JValue.cs +++ b/Src/Newtonsoft.Json/Linq/JValue.cs @@ -541,6 +541,24 @@ namespace Newtonsoft.Json.Linq return new JValue(value, JTokenType.String); } + /// + /// Creates a null value. + /// + /// A null value. + public static JValue CreateNull() + { + return new JValue(null, JTokenType.Null); + } + + /// + /// Creates a null value. + /// + /// A null value. + public static JValue CreateUndefined() + { + return new JValue(null, JTokenType.Undefined); + } + private static JTokenType GetValueType(JTokenType? current, object value) { if (value == null) diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs index 9d2b4f38..0af92d13 100644 --- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs @@ -91,5 +91,5 @@ using System.Security; // by using the '*' as shown below: [assembly: AssemblyVersion("6.0.0.0")] -[assembly: AssemblyFileVersion("6.0.3.17227")] +[assembly: AssemblyFileVersion("6.0.3.17229")] [assembly: CLSCompliant(true)] diff --git a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs index 4394d913..011a4383 100644 --- a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs +++ b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs @@ -485,7 +485,7 @@ namespace Newtonsoft.Json.Serialization // convert object value to JToken so it is compatible with dictionary // could happen because of primitive types, type name handling and references if (isJTokenValueType && !(value is JToken)) - value = (value != null) ? JToken.FromObject(value) : new JValue(null, JTokenType.Null); + value = (value != null) ? JToken.FromObject(value) : JValue.CreateNull(); setExtensionDataDictionaryValue(dictionary, key, value); };