-Code reformat
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 2012
|
# Visual Studio 2013
|
||||||
|
VisualStudioVersion = 12.0.21005.1
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lib", "Lib", "{620042D9-2753-48F5-BEDE-3905248781D2}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lib", "Lib", "{620042D9-2753-48F5-BEDE-3905248781D2}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
Lib\NUnit\DotNet\nunit.framework.dll = Lib\NUnit\DotNet\nunit.framework.dll
|
Lib\NUnit\DotNet\nunit.framework.dll = Lib\NUnit\DotNet\nunit.framework.dll
|
||||||
|
|||||||
@@ -1431,7 +1431,7 @@ namespace Newtonsoft.Json.Tests.Bson
|
|||||||
#if !(WINDOWS_PHONE || SILVERLIGHT || NET20 || NET35 || NETFX_CORE)
|
#if !(WINDOWS_PHONE || SILVERLIGHT || NET20 || NET35 || NETFX_CORE)
|
||||||
public void Utf8Text()
|
public void Utf8Text()
|
||||||
{
|
{
|
||||||
string badText =System.IO.File.ReadAllText(@"PoisonText.txt");
|
string badText = System.IO.File.ReadAllText(@"PoisonText.txt");
|
||||||
var j = new JObject();
|
var j = new JObject();
|
||||||
j["test"] = badText;
|
j["test"] = badText;
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ using System.Globalization;
|
|||||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||||
#else
|
#else
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Tests.Bson
|
namespace Newtonsoft.Json.Tests.Bson
|
||||||
@@ -253,7 +254,7 @@ namespace Newtonsoft.Json.Tests.Bson
|
|||||||
ExpiryDate = new DateTime(2000, 9, 28, 3, 59, 58, DateTimeKind.Local),
|
ExpiryDate = new DateTime(2000, 9, 28, 3, 59, 58, DateTimeKind.Local),
|
||||||
Name = "BSON!",
|
Name = "BSON!",
|
||||||
Price = -0.1m,
|
Price = -0.1m,
|
||||||
Sizes = new [] { "First", "Second" }
|
Sizes = new[] { "First", "Second" }
|
||||||
});
|
});
|
||||||
s1.Establised = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Local);
|
s1.Establised = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Local);
|
||||||
|
|
||||||
@@ -262,7 +263,7 @@ namespace Newtonsoft.Json.Tests.Bson
|
|||||||
|
|
||||||
ms.Seek(0, SeekOrigin.Begin);
|
ms.Seek(0, SeekOrigin.Begin);
|
||||||
BsonReader reader = new BsonReader(ms);
|
BsonReader reader = new BsonReader(ms);
|
||||||
Store s2 = (Store)serializer.Deserialize(reader, typeof (Store));
|
Store s2 = (Store)serializer.Deserialize(reader, typeof(Store));
|
||||||
|
|
||||||
Assert.AreNotEqual(s1, s2);
|
Assert.AreNotEqual(s1, s2);
|
||||||
Assert.AreEqual(s1.Color, s2.Color);
|
Assert.AreEqual(s1.Color, s2.Color);
|
||||||
@@ -371,7 +372,7 @@ namespace Newtonsoft.Json.Tests.Bson
|
|||||||
|
|
||||||
ms.Seek(0, SeekOrigin.Begin);
|
ms.Seek(0, SeekOrigin.Begin);
|
||||||
BsonReader reader = new BsonReader(ms);
|
BsonReader reader = new BsonReader(ms);
|
||||||
GoogleMapGeocoderStructure bsonGoogleMapGeocoder = (GoogleMapGeocoderStructure)serializer.Deserialize(reader, typeof (GoogleMapGeocoderStructure));
|
GoogleMapGeocoderStructure bsonGoogleMapGeocoder = (GoogleMapGeocoderStructure)serializer.Deserialize(reader, typeof(GoogleMapGeocoderStructure));
|
||||||
|
|
||||||
Assert.IsNotNull(bsonGoogleMapGeocoder);
|
Assert.IsNotNull(bsonGoogleMapGeocoder);
|
||||||
Assert.AreEqual("1600 Amphitheatre Parkway, Mountain View, CA, USA", bsonGoogleMapGeocoder.Name);
|
Assert.AreEqual("1600 Amphitheatre Parkway, Mountain View, CA, USA", bsonGoogleMapGeocoder.Name);
|
||||||
@@ -514,7 +515,7 @@ namespace Newtonsoft.Json.Tests.Bson
|
|||||||
MemoryStream ms = new MemoryStream();
|
MemoryStream ms = new MemoryStream();
|
||||||
BsonWriter writer = new BsonWriter(ms);
|
BsonWriter writer = new BsonWriter(ms);
|
||||||
|
|
||||||
byte[] oid = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
|
byte[] oid = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
|
||||||
|
|
||||||
writer.WriteStartObject();
|
writer.WriteStartObject();
|
||||||
writer.WritePropertyName("_oid");
|
writer.WritePropertyName("_oid");
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ using System.Text;
|
|||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ using System.Collections.Generic;
|
|||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
|
|||||||
@@ -169,7 +169,6 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
}", json);
|
}", json);
|
||||||
|
|
||||||
Assert.IsNotNull(deserializedDs);
|
Assert.IsNotNull(deserializedDs);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -455,4 +454,5 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -303,4 +303,5 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -73,10 +73,10 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
o.String = "String!";
|
o.String = "String!";
|
||||||
o.Integer = 234;
|
o.Integer = 234;
|
||||||
o.Float = 1.23d;
|
o.Float = 1.23d;
|
||||||
o.List = new List<string> {"First", "Second", "Third"};
|
o.List = new List<string> { "First", "Second", "Third" };
|
||||||
o.Object = new Dictionary<string, object>
|
o.Object = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{"First", 1}
|
{ "First", 1 }
|
||||||
};
|
};
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(d, Formatting.Indented);
|
string json = JsonConvert.SerializeObject(d, Formatting.Indented);
|
||||||
@@ -183,7 +183,6 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
|
|
||||||
Assert.AreEqual(null, c.Expando);
|
Assert.AreEqual(null, c.Expando);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
string json = @"{""DateTimeField"":""""}";
|
string json = @"{""DateTimeField"":""""}";
|
||||||
|
|
||||||
NullableDateTimeTestClass c = JsonConvert.DeserializeObject<NullableDateTimeTestClass>(json,
|
NullableDateTimeTestClass c = JsonConvert.DeserializeObject<NullableDateTimeTestClass>(json,
|
||||||
new JsonSerializerSettings { Converters = new [] {new IsoDateTimeConverter()}});
|
new JsonSerializerSettings { Converters = new[] { new IsoDateTimeConverter() } });
|
||||||
Assert.AreEqual(null, c.DateTimeField);
|
Assert.AreEqual(null, c.DateTimeField);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +273,6 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
Console.WriteLine(jsonText);
|
Console.WriteLine(jsonText);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,6 +220,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
{
|
{
|
||||||
public object Object1 { get; set; }
|
public object Object1 { get; set; }
|
||||||
public object Object2 { get; set; }
|
public object Object2 { get; set; }
|
||||||
|
|
||||||
[JsonConverter(typeof(DateIntConverter))]
|
[JsonConverter(typeof(DateIntConverter))]
|
||||||
public object ObjectNotHandled { get; set; }
|
public object ObjectNotHandled { get; set; }
|
||||||
}
|
}
|
||||||
@@ -228,7 +229,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
{
|
{
|
||||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||||
{
|
{
|
||||||
DateTime? d = (DateTime?) value;
|
DateTime? d = (DateTime?)value;
|
||||||
if (d == null)
|
if (d == null)
|
||||||
writer.WriteNull();
|
writer.WriteNull();
|
||||||
else
|
else
|
||||||
@@ -242,7 +243,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
|
|
||||||
public override bool CanConvert(Type objectType)
|
public override bool CanConvert(Type objectType)
|
||||||
{
|
{
|
||||||
return objectType == typeof (DateTime) || objectType == typeof (DateTime?);
|
return objectType == typeof(DateTime) || objectType == typeof(DateTime?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
// OTHER DEALINGS IN THE SOFTWARE.
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#if NETFX_CORE
|
#if NETFX_CORE
|
||||||
using System;
|
using System;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ using Newtonsoft.Json.Bson;
|
|||||||
using Newtonsoft.Json.Utilities;
|
using Newtonsoft.Json.Utilities;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
@@ -43,6 +44,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
{
|
{
|
||||||
[JsonProperty("_id")]
|
[JsonProperty("_id")]
|
||||||
public BsonObjectId Id { get; set; }
|
public BsonObjectId Id { get; set; }
|
||||||
|
|
||||||
[JsonProperty("test")]
|
[JsonProperty("test")]
|
||||||
public string Test { get; set; }
|
public string Test { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
|
|
||||||
string json = JsonConvert.SerializeObject(regex, Formatting.Indented, new JsonSerializerSettings
|
string json = JsonConvert.SerializeObject(regex, Formatting.Indented, new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
Converters = {new RegexConverter(),new StringEnumConverter() { CamelCaseText = true }},
|
Converters = { new RegexConverter(), new StringEnumConverter() { CamelCaseText = true } },
|
||||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
enumClass.NullableStoreColor1 = StoreColor.DarkGoldenrod;
|
enumClass.NullableStoreColor1 = StoreColor.DarkGoldenrod;
|
||||||
enumClass.NullableStoreColor2 = null;
|
enumClass.NullableStoreColor2 = null;
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(enumClass, Formatting.Indented, new StringEnumConverter {CamelCaseText = true});
|
string json = JsonConvert.SerializeObject(enumClass, Formatting.Indented, new StringEnumConverter { CamelCaseText = true });
|
||||||
|
|
||||||
Assert.AreEqual(@"{
|
Assert.AreEqual(@"{
|
||||||
""StoreColor"": ""red"",
|
""StoreColor"": ""red"",
|
||||||
@@ -197,8 +197,8 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
public void SerializeEnumClassUndefined()
|
public void SerializeEnumClassUndefined()
|
||||||
{
|
{
|
||||||
EnumClass enumClass = new EnumClass();
|
EnumClass enumClass = new EnumClass();
|
||||||
enumClass.StoreColor = (StoreColor) 1000;
|
enumClass.StoreColor = (StoreColor)1000;
|
||||||
enumClass.NullableStoreColor1 = (StoreColor) 1000;
|
enumClass.NullableStoreColor1 = (StoreColor)1000;
|
||||||
enumClass.NullableStoreColor2 = null;
|
enumClass.NullableStoreColor2 = null;
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(enumClass, Formatting.Indented, new StringEnumConverter());
|
string json = JsonConvert.SerializeObject(enumClass, Formatting.Indented, new StringEnumConverter());
|
||||||
@@ -232,7 +232,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
{
|
{
|
||||||
NegativeEnumClass negativeEnumClass = new NegativeEnumClass();
|
NegativeEnumClass negativeEnumClass = new NegativeEnumClass();
|
||||||
negativeEnumClass.Value1 = NegativeEnum.Negative;
|
negativeEnumClass.Value1 = NegativeEnum.Negative;
|
||||||
negativeEnumClass.Value2 = (NegativeEnum) int.MinValue;
|
negativeEnumClass.Value2 = (NegativeEnum)int.MinValue;
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(negativeEnumClass, Formatting.Indented, new StringEnumConverter());
|
string json = JsonConvert.SerializeObject(negativeEnumClass, Formatting.Indented, new StringEnumConverter());
|
||||||
|
|
||||||
@@ -253,7 +253,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
NegativeEnumClass negativeEnumClass = JsonConvert.DeserializeObject<NegativeEnumClass>(json, new StringEnumConverter());
|
NegativeEnumClass negativeEnumClass = JsonConvert.DeserializeObject<NegativeEnumClass>(json, new StringEnumConverter());
|
||||||
|
|
||||||
Assert.AreEqual(NegativeEnum.Negative, negativeEnumClass.Value1);
|
Assert.AreEqual(NegativeEnum.Negative, negativeEnumClass.Value1);
|
||||||
Assert.AreEqual((NegativeEnum) int.MinValue, negativeEnumClass.Value2);
|
Assert.AreEqual((NegativeEnum)int.MinValue, negativeEnumClass.Value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -268,7 +268,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
EnumClass enumClass = JsonConvert.DeserializeObject<EnumClass>(json, new StringEnumConverter());
|
EnumClass enumClass = JsonConvert.DeserializeObject<EnumClass>(json, new StringEnumConverter());
|
||||||
|
|
||||||
Assert.AreEqual(StoreColor.Red | StoreColor.White, enumClass.StoreColor);
|
Assert.AreEqual(StoreColor.Red | StoreColor.White, enumClass.StoreColor);
|
||||||
Assert.AreEqual((StoreColor) 0, enumClass.NullableStoreColor1);
|
Assert.AreEqual((StoreColor)0, enumClass.NullableStoreColor1);
|
||||||
Assert.AreEqual(StoreColor.Red | StoreColor.White | StoreColor.Black, enumClass.NullableStoreColor2);
|
Assert.AreEqual(StoreColor.Red | StoreColor.White | StoreColor.Black, enumClass.NullableStoreColor2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,8 +299,8 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
|
|
||||||
EnumClass enumClass = JsonConvert.DeserializeObject<EnumClass>(json, new StringEnumConverter());
|
EnumClass enumClass = JsonConvert.DeserializeObject<EnumClass>(json, new StringEnumConverter());
|
||||||
|
|
||||||
Assert.AreEqual((StoreColor) 1000, enumClass.StoreColor);
|
Assert.AreEqual((StoreColor)1000, enumClass.StoreColor);
|
||||||
Assert.AreEqual((StoreColor) 1000, enumClass.NullableStoreColor1);
|
Assert.AreEqual((StoreColor)1000, enumClass.NullableStoreColor1);
|
||||||
Assert.AreEqual(null, enumClass.NullableStoreColor2);
|
Assert.AreEqual(null, enumClass.NullableStoreColor2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,7 +312,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
Enum = FlagsTestEnum.First | FlagsTestEnum.Second
|
Enum = FlagsTestEnum.First | FlagsTestEnum.Second
|
||||||
};
|
};
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(c, Formatting.Indented, new StringEnumConverter {CamelCaseText = true});
|
string json = JsonConvert.SerializeObject(c, Formatting.Indented, new StringEnumConverter { CamelCaseText = true });
|
||||||
Assert.AreEqual(@"{
|
Assert.AreEqual(@"{
|
||||||
""Enum"": ""first, second""
|
""Enum"": ""first, second""
|
||||||
}", json);
|
}", json);
|
||||||
@@ -325,7 +325,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
""Enum"": ""first, second""
|
""Enum"": ""first, second""
|
||||||
}";
|
}";
|
||||||
|
|
||||||
EnumContainer<FlagsTestEnum> c = JsonConvert.DeserializeObject<EnumContainer<FlagsTestEnum>>(json, new StringEnumConverter {CamelCaseText = true});
|
EnumContainer<FlagsTestEnum> c = JsonConvert.DeserializeObject<EnumContainer<FlagsTestEnum>>(json, new StringEnumConverter { CamelCaseText = true });
|
||||||
Assert.AreEqual(FlagsTestEnum.First | FlagsTestEnum.Second, c.Enum);
|
Assert.AreEqual(FlagsTestEnum.First | FlagsTestEnum.Second, c.Enum);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,10 +380,10 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
Foo.Bat,
|
Foo.Bat,
|
||||||
Foo.SerializeAsBaz,
|
Foo.SerializeAsBaz,
|
||||||
Foo.FooBar | Foo.SerializeAsBaz,
|
Foo.FooBar | Foo.SerializeAsBaz,
|
||||||
(Foo) int.MaxValue
|
(Foo)int.MaxValue
|
||||||
};
|
};
|
||||||
|
|
||||||
string json1 = JsonConvert.SerializeObject(lfoo, Formatting.Indented, new StringEnumConverter {CamelCaseText = true});
|
string json1 = JsonConvert.SerializeObject(lfoo, Formatting.Indented, new StringEnumConverter { CamelCaseText = true });
|
||||||
|
|
||||||
Assert.AreEqual(@"[
|
Assert.AreEqual(@"[
|
||||||
""Bat, baz"",
|
""Bat, baz"",
|
||||||
@@ -402,11 +402,11 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
Assert.AreEqual(Foo.Bat, foos[2]);
|
Assert.AreEqual(Foo.Bat, foos[2]);
|
||||||
Assert.AreEqual(Foo.SerializeAsBaz, foos[3]);
|
Assert.AreEqual(Foo.SerializeAsBaz, foos[3]);
|
||||||
Assert.AreEqual(Foo.FooBar | Foo.SerializeAsBaz, foos[4]);
|
Assert.AreEqual(Foo.FooBar | Foo.SerializeAsBaz, foos[4]);
|
||||||
Assert.AreEqual((Foo) int.MaxValue, foos[5]);
|
Assert.AreEqual((Foo)int.MaxValue, foos[5]);
|
||||||
|
|
||||||
List<Bar> lbar = new List<Bar>() {Bar.FooBar, Bar.Bat, Bar.SerializeAsBaz};
|
List<Bar> lbar = new List<Bar>() { Bar.FooBar, Bar.Bat, Bar.SerializeAsBaz };
|
||||||
|
|
||||||
string json2 = JsonConvert.SerializeObject(lbar, Formatting.Indented, new StringEnumConverter {CamelCaseText = true});
|
string json2 = JsonConvert.SerializeObject(lbar, Formatting.Indented, new StringEnumConverter { CamelCaseText = true });
|
||||||
|
|
||||||
Assert.AreEqual(@"[
|
Assert.AreEqual(@"[
|
||||||
""foo_bar"",
|
""foo_bar"",
|
||||||
@@ -424,7 +424,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
|
|
||||||
// Define other methods and classes here
|
// Define other methods and classes here
|
||||||
[Flags]
|
[Flags]
|
||||||
[JsonConverter(typeof (StringEnumConverter))]
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
private enum Foo
|
private enum Foo
|
||||||
{
|
{
|
||||||
[EnumMember(Value = "foo_bar")]
|
[EnumMember(Value = "foo_bar")]
|
||||||
@@ -435,7 +435,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
SerializeAsBaz = 0x4,
|
SerializeAsBaz = 0x4,
|
||||||
};
|
};
|
||||||
|
|
||||||
[JsonConverter(typeof (StringEnumConverter))]
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
private enum Bar
|
private enum Bar
|
||||||
{
|
{
|
||||||
[EnumMember(Value = "foo_bar")]
|
[EnumMember(Value = "foo_bar")]
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ using System;
|
|||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
@@ -39,10 +40,10 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
{
|
{
|
||||||
public VersionClass(string version1, string version2)
|
public VersionClass(string version1, string version2)
|
||||||
{
|
{
|
||||||
this.StringProperty1 = "StringProperty1";
|
StringProperty1 = "StringProperty1";
|
||||||
this.Version1 = new Version(version1);
|
Version1 = new Version(version1);
|
||||||
this.Version2 = new Version(version2);
|
Version2 = new Version(version2);
|
||||||
this.StringProperty2 = "StringProperty2";
|
StringProperty2 = "StringProperty2";
|
||||||
}
|
}
|
||||||
|
|
||||||
public VersionClass()
|
public VersionClass()
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ using Newtonsoft.Json.Utilities;
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
#if !NET20
|
#if !NET20
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Tests.Converters
|
namespace Newtonsoft.Json.Tests.Converters
|
||||||
@@ -63,7 +64,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
}
|
}
|
||||||
else if (node is XmlAttribute)
|
else if (node is XmlAttribute)
|
||||||
{
|
{
|
||||||
XmlAttribute attribute = (XmlAttribute) node;
|
XmlAttribute attribute = (XmlAttribute)node;
|
||||||
xNode = new XAttribute(XName.Get(attribute.LocalName, attribute.NamespaceURI), attribute.Value);
|
xNode = new XAttribute(XName.Get(attribute.LocalName, attribute.NamespaceURI), attribute.Value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -95,14 +96,14 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
if (deserializeRootElementName != null)
|
if (deserializeRootElementName != null)
|
||||||
converter.DeserializeRootElementName = deserializeRootElementName;
|
converter.DeserializeRootElementName = deserializeRootElementName;
|
||||||
|
|
||||||
XmlNode node = (XmlNode)converter.ReadJson(reader, typeof (XmlDocument), null, new JsonSerializer());
|
XmlNode node = (XmlNode)converter.ReadJson(reader, typeof(XmlDocument), null, new JsonSerializer());
|
||||||
|
|
||||||
#if !NET20
|
#if !NET20
|
||||||
string xmlText = node.OuterXml;
|
string xmlText = node.OuterXml;
|
||||||
|
|
||||||
reader = new JsonTextReader(new StringReader(json));
|
reader = new JsonTextReader(new StringReader(json));
|
||||||
reader.Read();
|
reader.Read();
|
||||||
XDocument d = (XDocument) converter.ReadJson(reader, typeof (XDocument), null, new JsonSerializer());
|
XDocument d = (XDocument)converter.ReadJson(reader, typeof(XDocument), null, new JsonSerializer());
|
||||||
|
|
||||||
string linqXmlText = d.ToString(SaveOptions.DisableFormatting);
|
string linqXmlText = d.ToString(SaveOptions.DisableFormatting);
|
||||||
if (d.Declaration != null)
|
if (d.Declaration != null)
|
||||||
@@ -524,10 +525,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
{
|
{
|
||||||
ExceptionAssert.Throws<JsonSerializationException>(
|
ExceptionAssert.Throws<JsonSerializationException>(
|
||||||
"XmlNodeConverter can only convert JSON that begins with an object.",
|
"XmlNodeConverter can only convert JSON that begins with an object.",
|
||||||
() =>
|
() => { XmlDocument newDoc = (XmlDocument)JsonConvert.DeserializeXmlNode(@"[1]"); });
|
||||||
{
|
|
||||||
XmlDocument newDoc = (XmlDocument)JsonConvert.DeserializeXmlNode(@"[1]");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -535,10 +533,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
{
|
{
|
||||||
ExceptionAssert.Throws<JsonSerializationException>(
|
ExceptionAssert.Throws<JsonSerializationException>(
|
||||||
"JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName.",
|
"JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName.",
|
||||||
() =>
|
() => { XmlDocument newDoc = (XmlDocument)JsonConvert.DeserializeXmlNode(@"{Prop1:1,Prop2:2}"); });
|
||||||
{
|
|
||||||
XmlDocument newDoc = (XmlDocument)JsonConvert.DeserializeXmlNode(@"{Prop1:1,Prop2:2}");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -656,10 +651,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonSerializationException>(
|
ExceptionAssert.Throws<JsonSerializationException>(
|
||||||
"JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName.",
|
"JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName.",
|
||||||
() =>
|
() => { JsonConvert.DeserializeXmlNode(json); });
|
||||||
{
|
|
||||||
JsonConvert.DeserializeXmlNode(json);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !NET20
|
#if !NET20
|
||||||
@@ -670,10 +662,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonSerializationException>(
|
ExceptionAssert.Throws<JsonSerializationException>(
|
||||||
"JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName.",
|
"JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName.",
|
||||||
() =>
|
() => { JsonConvert.DeserializeXNode(json); });
|
||||||
{
|
|
||||||
JsonConvert.DeserializeXNode(json);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1136,10 +1125,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonSerializationException>(
|
ExceptionAssert.Throws<JsonSerializationException>(
|
||||||
"XmlNodeConverter cannot convert JSON with an empty property name to XML.",
|
"XmlNodeConverter cannot convert JSON with an empty property name to XML.",
|
||||||
() =>
|
() => { DeserializeXmlNode(json); });
|
||||||
{
|
|
||||||
DeserializeXmlNode(json);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -1925,4 +1911,5 @@ namespace Newtonsoft.Json.Tests.Converters
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -71,7 +71,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
property.ShouldSerialize =
|
property.ShouldSerialize =
|
||||||
instance =>
|
instance =>
|
||||||
{
|
{
|
||||||
Employee e = (Employee) instance;
|
Employee e = (Employee)instance;
|
||||||
return e.Manager != e;
|
return e.Manager != e;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -152,7 +152,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
mike.Manager = mike;
|
mike.Manager = mike;
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(
|
string json = JsonConvert.SerializeObject(
|
||||||
new[] {joe, mike},
|
new[] { joe, mike },
|
||||||
Formatting.Indented,
|
Formatting.Indented,
|
||||||
new JsonSerializerSettings
|
new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
@@ -170,8 +170,8 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
""Name"": ""Mike Manager""
|
""Name"": ""Mike Manager""
|
||||||
}
|
}
|
||||||
]", json);
|
]", json);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -177,7 +177,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
//}
|
//}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -158,12 +158,12 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
schema.Type = JsonSchemaType.Object;
|
schema.Type = JsonSchemaType.Object;
|
||||||
schema.Properties = new Dictionary<string, JsonSchema>
|
schema.Properties = new Dictionary<string, JsonSchema>
|
||||||
{
|
{
|
||||||
{"name", new JsonSchema {Type = JsonSchemaType.String}},
|
{ "name", new JsonSchema { Type = JsonSchemaType.String } },
|
||||||
{
|
{
|
||||||
"hobbies", new JsonSchema
|
"hobbies", new JsonSchema
|
||||||
{
|
{
|
||||||
Type = JsonSchemaType.Array,
|
Type = JsonSchemaType.Array,
|
||||||
Items = new List<JsonSchema> { new JsonSchema {Type = JsonSchemaType.String} }
|
Items = new List<JsonSchema> { new JsonSchema { Type = JsonSchemaType.String } }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -181,4 +181,5 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -319,7 +319,8 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
|
|
||||||
var categories =
|
var categories =
|
||||||
from c in rss["channel"]["item"].Children()["category"].Values<string>()
|
from c in rss["channel"]["item"].Children()["category"].Values<string>()
|
||||||
group c by c into g
|
group c by c
|
||||||
|
into g
|
||||||
orderby g.Count() descending
|
orderby g.Count() descending
|
||||||
select new { Category = g.Key, Count = g.Count() };
|
select new { Category = g.Key, Count = g.Count() };
|
||||||
|
|
||||||
@@ -457,4 +458,5 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -218,4 +218,5 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -147,4 +147,5 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -13,8 +13,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
|
|||||||
#region Usage
|
#region Usage
|
||||||
JObject o1 = new JObject
|
JObject o1 = new JObject
|
||||||
{
|
{
|
||||||
{"String", "A string!"},
|
{ "String", "A string!" },
|
||||||
{"Items", new JArray(1, 2)}
|
{ "Items", new JArray(1, 2) }
|
||||||
};
|
};
|
||||||
|
|
||||||
Console.WriteLine(o1.ToString());
|
Console.WriteLine(o1.ToString());
|
||||||
@@ -26,7 +26,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
|
|||||||
// ]
|
// ]
|
||||||
// }
|
// }
|
||||||
|
|
||||||
JObject o2 = (JObject) o1.DeepClone();
|
JObject o2 = (JObject)o1.DeepClone();
|
||||||
|
|
||||||
Console.WriteLine(o2.ToString());
|
Console.WriteLine(o2.ToString());
|
||||||
// {
|
// {
|
||||||
|
|||||||
+2
-2
@@ -13,8 +13,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
|
|||||||
#region Usage
|
#region Usage
|
||||||
JObject o = new JObject
|
JObject o = new JObject
|
||||||
{
|
{
|
||||||
{"Cpu", "Intel"},
|
{ "Cpu", "Intel" },
|
||||||
{"Memory", 32},
|
{ "Memory", 32 },
|
||||||
{
|
{
|
||||||
"Drives", new JArray
|
"Drives", new JArray
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
|
|||||||
#region Usage
|
#region Usage
|
||||||
JObject o = new JObject
|
JObject o = new JObject
|
||||||
{
|
{
|
||||||
{"Cpu", "Intel"},
|
{ "Cpu", "Intel" },
|
||||||
{"Memory", 32},
|
{ "Memory", 32 },
|
||||||
{
|
{
|
||||||
"Drives", new JArray
|
"Drives", new JArray
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
|
|||||||
#region Usage
|
#region Usage
|
||||||
JObject o = new JObject
|
JObject o = new JObject
|
||||||
{
|
{
|
||||||
{"name1", "value1"},
|
{ "name1", "value1" },
|
||||||
{"name2", "value2"}
|
{ "name2", "value2" }
|
||||||
};
|
};
|
||||||
|
|
||||||
JsonWriter writer = o.CreateWriter();
|
JsonWriter writer = o.CreateWriter();
|
||||||
|
|||||||
@@ -23,16 +23,16 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
|
|||||||
|
|
||||||
JObject o1 = new JObject
|
JObject o1 = new JObject
|
||||||
{
|
{
|
||||||
{"Integer", 12345},
|
{ "Integer", 12345 },
|
||||||
{"String", "A string"},
|
{ "String", "A string" },
|
||||||
{"Items", new JArray(1, 2)}
|
{ "Items", new JArray(1, 2) }
|
||||||
};
|
};
|
||||||
|
|
||||||
JObject o2 = new JObject
|
JObject o2 = new JObject
|
||||||
{
|
{
|
||||||
{"Integer", 12345},
|
{ "Integer", 12345 },
|
||||||
{"String", "A string"},
|
{ "String", "A string" },
|
||||||
{"Items", new JArray(1, 2)}
|
{ "Items", new JArray(1, 2) }
|
||||||
};
|
};
|
||||||
|
|
||||||
Console.WriteLine(JToken.DeepEquals(o1, o2));
|
Console.WriteLine(JToken.DeepEquals(o1, o2));
|
||||||
|
|||||||
@@ -40,11 +40,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
|
|||||||
|
|
||||||
IList<BlogPost> blogPosts = blogPostArray.Select(p => new BlogPost
|
IList<BlogPost> blogPosts = blogPostArray.Select(p => new BlogPost
|
||||||
{
|
{
|
||||||
Title = (string) p["Title"],
|
Title = (string)p["Title"],
|
||||||
AuthorName = (string) p["Author"]["Name"],
|
AuthorName = (string)p["Author"]["Name"],
|
||||||
AuthorTwitter = (string) p["Author"]["Twitter"],
|
AuthorTwitter = (string)p["Author"]["Twitter"],
|
||||||
PostedDate = (DateTime) p["Date"],
|
PostedDate = (DateTime)p["Date"],
|
||||||
Body = HttpUtility.HtmlDecode((string) p["BodyHtml"])
|
Body = HttpUtility.HtmlDecode((string)p["BodyHtml"])
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
Console.WriteLine(blogPosts[0].Body);
|
Console.WriteLine(blogPosts[0].Body);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
|
|||||||
JObject o = new JObject
|
JObject o = new JObject
|
||||||
{
|
{
|
||||||
{ "name1", "value1" },
|
{ "name1", "value1" },
|
||||||
{ "name2", "value2"}
|
{ "name2", "value2" }
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (JProperty property in o.Properties())
|
foreach (JProperty property in o.Properties())
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
|
|||||||
|
|
||||||
channel.Property("description").AddAfterSelf(new JProperty("new", "New value"));
|
channel.Property("description").AddAfterSelf(new JProperty("new", "New value"));
|
||||||
|
|
||||||
JArray item = (JArray) channel["item"];
|
JArray item = (JArray)channel["item"];
|
||||||
item.Add("Item 1");
|
item.Add("Item 1");
|
||||||
item.Add("Item 2");
|
item.Add("Item 2");
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
|
|||||||
|
|
||||||
var categories =
|
var categories =
|
||||||
from c in rss["channel"]["item"].Children()["category"].Values<string>()
|
from c in rss["channel"]["item"].Children()["category"].Values<string>()
|
||||||
group c by c into g
|
group c by c
|
||||||
|
into g
|
||||||
orderby g.Count() descending
|
orderby g.Count() descending
|
||||||
select new { Category = g.Key, Count = g.Count() };
|
select new { Category = g.Key, Count = g.Count() };
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
|
|||||||
using (StreamReader file = File.OpenText(@"c:\videogames.json"))
|
using (StreamReader file = File.OpenText(@"c:\videogames.json"))
|
||||||
using (JsonTextReader reader = new JsonTextReader(file))
|
using (JsonTextReader reader = new JsonTextReader(file))
|
||||||
{
|
{
|
||||||
JObject o2 = (JObject) JToken.ReadFrom(reader);
|
JObject o2 = (JObject)JToken.ReadFrom(reader);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,16 +39,16 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
|
|||||||
JArray blogPostsArray = new JArray(
|
JArray blogPostsArray = new JArray(
|
||||||
blogPosts.Select(p => new JObject
|
blogPosts.Select(p => new JObject
|
||||||
{
|
{
|
||||||
{"Title", p.Title},
|
{ "Title", p.Title },
|
||||||
{
|
{
|
||||||
"Author", new JObject
|
"Author", new JObject
|
||||||
{
|
{
|
||||||
{"Name", p.AuthorName},
|
{ "Name", p.AuthorName },
|
||||||
{"Twitter", p.AuthorTwitter}
|
{ "Twitter", p.AuthorTwitter }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{"Date", p.PostedDate},
|
{ "Date", p.PostedDate },
|
||||||
{"BodyHtml", HttpUtility.HtmlEncode(p.Body)},
|
{ "BodyHtml", HttpUtility.HtmlEncode(p.Body) },
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
|
|||||||
#region Usage
|
#region Usage
|
||||||
JObject o = new JObject
|
JObject o = new JObject
|
||||||
{
|
{
|
||||||
{"name1","value1"},
|
{ "name1", "value1" },
|
||||||
{"name2","value2"}
|
{ "name2", "value2" }
|
||||||
};
|
};
|
||||||
|
|
||||||
MemoryStream ms = new MemoryStream();
|
MemoryStream ms = new MemoryStream();
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
|
|||||||
schema.Type = JsonSchemaType.Object;
|
schema.Type = JsonSchemaType.Object;
|
||||||
schema.Properties = new Dictionary<string, JsonSchema>
|
schema.Properties = new Dictionary<string, JsonSchema>
|
||||||
{
|
{
|
||||||
{"name", new JsonSchema {Type = JsonSchemaType.String}},
|
{ "name", new JsonSchema { Type = JsonSchemaType.String } },
|
||||||
{
|
{
|
||||||
"hobbies", new JsonSchema
|
"hobbies", new JsonSchema
|
||||||
{
|
{
|
||||||
Type = JsonSchemaType.Array,
|
Type = JsonSchemaType.Array,
|
||||||
Items = new List<JsonSchema> { new JsonSchema {Type = JsonSchemaType.String} }
|
Items = new List<JsonSchema> { new JsonSchema { Type = JsonSchemaType.String } }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
|||||||
public class DynamicContractResolver : DefaultContractResolver
|
public class DynamicContractResolver : DefaultContractResolver
|
||||||
{
|
{
|
||||||
private readonly char _startingWithChar;
|
private readonly char _startingWithChar;
|
||||||
|
|
||||||
public DynamicContractResolver(char startingWithChar)
|
public DynamicContractResolver(char startingWithChar)
|
||||||
{
|
{
|
||||||
_startingWithChar = startingWithChar;
|
_startingWithChar = startingWithChar;
|
||||||
|
|||||||
+2
-1
@@ -18,6 +18,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
|||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public int Size { get; set; }
|
public int Size { get; set; }
|
||||||
}
|
}
|
||||||
@@ -30,7 +31,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
|||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
Name = "ImportantLegalDocuments.docx",
|
Name = "ImportantLegalDocuments.docx",
|
||||||
Size = 50*1024
|
Size = 50 * 1024
|
||||||
};
|
};
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(file, Formatting.Indented);
|
string json = JsonConvert.SerializeObject(file, Formatting.Indented);
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
|||||||
public void Example()
|
public void Example()
|
||||||
{
|
{
|
||||||
#region Usage
|
#region Usage
|
||||||
var definition = new {Name = ""};
|
var definition = new { Name = "" };
|
||||||
|
|
||||||
string json1 = @"{'Name':'James'}";
|
string json1 = @"{'Name':'James'}";
|
||||||
var customer1 = JsonConvert.DeserializeAnonymousType(json1, definition);
|
var customer1 = JsonConvert.DeserializeAnonymousType(json1, definition);
|
||||||
|
|||||||
+1
-1
@@ -47,7 +47,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
|||||||
Console.WriteLine(person.GetType().Name);
|
Console.WriteLine(person.GetType().Name);
|
||||||
// Employee
|
// Employee
|
||||||
|
|
||||||
Employee employee = (Employee) person;
|
Employee employee = (Employee)person;
|
||||||
|
|
||||||
Console.WriteLine(employee.JobTitle);
|
Console.WriteLine(employee.JobTitle);
|
||||||
// Capenter
|
// Capenter
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
|||||||
using (StreamReader file = File.OpenText(@"c:\movie.json"))
|
using (StreamReader file = File.OpenText(@"c:\movie.json"))
|
||||||
{
|
{
|
||||||
JsonSerializer serializer = new JsonSerializer();
|
JsonSerializer serializer = new JsonSerializer();
|
||||||
Movie movie2 = (Movie)serializer.Deserialize(file, typeof (Movie));
|
Movie movie2 = (Movie)serializer.Deserialize(file, typeof(Movie));
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
|||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public int Age { get; set; }
|
public int Age { get; set; }
|
||||||
|
|
||||||
public List<string> Roles
|
public List<string> Roles
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -27,6 +28,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
|||||||
}
|
}
|
||||||
set { _roles = value; }
|
set { _roles = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
|
|
||||||
[OnError]
|
[OnError]
|
||||||
|
|||||||
+2
-2
@@ -13,7 +13,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
|||||||
{
|
{
|
||||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||||
{
|
{
|
||||||
User user = (User) value;
|
User user = (User)value;
|
||||||
|
|
||||||
writer.WriteValue(user.UserName);
|
writer.WriteValue(user.UserName);
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
|||||||
|
|
||||||
public override bool CanConvert(Type objectType)
|
public override bool CanConvert(Type objectType)
|
||||||
{
|
{
|
||||||
return objectType == typeof (User);
|
return objectType == typeof(User);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
|||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public int Size { get; set; }
|
public int Size { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
|||||||
// appear last
|
// appear last
|
||||||
[JsonProperty(Order = 1)]
|
[JsonProperty(Order = 1)]
|
||||||
public bool Deleted { get; set; }
|
public bool Deleted { get; set; }
|
||||||
|
|
||||||
[JsonProperty(Order = 2)]
|
[JsonProperty(Order = 2)]
|
||||||
public DateTime DeletedDate { get; set; }
|
public DateTime DeletedDate { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
|||||||
{
|
{
|
||||||
public string FullName { get; set; }
|
public string FullName { get; set; }
|
||||||
public string EmailAddress { get; set; }
|
public string EmailAddress { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string PasswordHash { get; set; }
|
public string PasswordHash { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
|||||||
#region Usage
|
#region Usage
|
||||||
KnownTypesBinder knownTypesBinder = new KnownTypesBinder
|
KnownTypesBinder knownTypesBinder = new KnownTypesBinder
|
||||||
{
|
{
|
||||||
KnownTypes = new List<Type> {typeof (Car)}
|
KnownTypes = new List<Type> { typeof(Car) }
|
||||||
};
|
};
|
||||||
|
|
||||||
Car car = new Car
|
Car car = new Car
|
||||||
|
|||||||
@@ -271,6 +271,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public int Age { get; set; }
|
public int Age { get; set; }
|
||||||
|
|
||||||
public List<string> Roles
|
public List<string> Roles
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -282,6 +283,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
}
|
}
|
||||||
set { _roles = value; }
|
set { _roles = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
|
|
||||||
[OnError]
|
[OnError]
|
||||||
@@ -624,6 +626,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
// included in JSON
|
// included in JSON
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public decimal SalePrice { get; set; }
|
public decimal SalePrice { get; set; }
|
||||||
|
|
||||||
@@ -692,6 +695,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
// customize default values
|
// customize default values
|
||||||
[DefaultValue(30)]
|
[DefaultValue(30)]
|
||||||
public int FollowUpDays { get; set; }
|
public int FollowUpDays { get; set; }
|
||||||
|
|
||||||
[DefaultValue("")]
|
[DefaultValue("")]
|
||||||
public string FollowUpEmailAddress { get; set; }
|
public string FollowUpEmailAddress { get; set; }
|
||||||
}
|
}
|
||||||
@@ -738,6 +742,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
public class DynamicContractResolver : DefaultContractResolver
|
public class DynamicContractResolver : DefaultContractResolver
|
||||||
{
|
{
|
||||||
private readonly char _startingWithChar;
|
private readonly char _startingWithChar;
|
||||||
|
|
||||||
public DynamicContractResolver(char startingWithChar)
|
public DynamicContractResolver(char startingWithChar)
|
||||||
{
|
{
|
||||||
_startingWithChar = startingWithChar;
|
_startingWithChar = startingWithChar;
|
||||||
@@ -887,10 +892,10 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
{
|
{
|
||||||
string[,] famousCouples = new string[,]
|
string[,] famousCouples = new string[,]
|
||||||
{
|
{
|
||||||
{"Adam", "Eve"},
|
{ "Adam", "Eve" },
|
||||||
{"Bonnie", "Clyde"},
|
{ "Bonnie", "Clyde" },
|
||||||
{"Donald", "Daisy"},
|
{ "Donald", "Daisy" },
|
||||||
{"Han", "Leia"}
|
{ "Han", "Leia" }
|
||||||
};
|
};
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(famousCouples, Formatting.Indented);
|
string json = JsonConvert.SerializeObject(famousCouples, Formatting.Indented);
|
||||||
@@ -908,4 +913,5 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -171,4 +171,5 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -27,6 +27,7 @@ using System;
|
|||||||
using Newtonsoft.Json.Schema;
|
using Newtonsoft.Json.Schema;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ using Newtonsoft.Json.Tests.TestObjects;
|
|||||||
using Newtonsoft.Json.Utilities;
|
using Newtonsoft.Json.Utilities;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
@@ -405,10 +406,7 @@ now brown cow?", '"', true);
|
|||||||
public void ToStringInvalid()
|
public void ToStringInvalid()
|
||||||
{
|
{
|
||||||
ExceptionAssert.Throws<ArgumentException>("Unsupported type: System.Version. Use the JsonSerializer class to get the object's JSON representation.",
|
ExceptionAssert.Throws<ArgumentException>("Unsupported type: System.Version. Use the JsonSerializer class to get the object's JSON representation.",
|
||||||
() =>
|
() => { JsonConvert.ToString(new Version(1, 0)); });
|
||||||
{
|
|
||||||
JsonConvert.ToString(new Version(1, 0));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -819,7 +817,7 @@ now brown cow?", '"', true);
|
|||||||
long valueTicks = GetTicks(value);
|
long valueTicks = GetTicks(value);
|
||||||
long parsedTicks = GetTicks(parsed);
|
long parsedTicks = GetTicks(parsed);
|
||||||
|
|
||||||
valueTicks = (valueTicks/10000)*10000;
|
valueTicks = (valueTicks / 10000) * 10000;
|
||||||
|
|
||||||
Assert.AreEqual(valueTicks, parsedTicks);
|
Assert.AreEqual(valueTicks, parsedTicks);
|
||||||
}
|
}
|
||||||
@@ -886,7 +884,7 @@ now brown cow?", '"', true);
|
|||||||
|
|
||||||
Assert.AreEqual("42", task.Result);
|
Assert.AreEqual("42", task.Result);
|
||||||
|
|
||||||
task = JsonConvert.SerializeObjectAsync(new[] {1, 2, 3, 4, 5}, Formatting.Indented);
|
task = JsonConvert.SerializeObjectAsync(new[] { 1, 2, 3, 4, 5 }, Formatting.Indented);
|
||||||
task.Wait();
|
task.Wait();
|
||||||
|
|
||||||
Assert.AreEqual(@"[
|
Assert.AreEqual(@"[
|
||||||
@@ -912,7 +910,7 @@ now brown cow?", '"', true);
|
|||||||
|
|
||||||
Task<object> taskVersionArray = JsonConvert.DeserializeObjectAsync("['2.0']", typeof(Version[]), new JsonSerializerSettings
|
Task<object> taskVersionArray = JsonConvert.DeserializeObjectAsync("['2.0']", typeof(Version[]), new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
Converters = {new VersionConverter()}
|
Converters = { new VersionConverter() }
|
||||||
});
|
});
|
||||||
taskVersionArray.Wait();
|
taskVersionArray.Wait();
|
||||||
|
|
||||||
@@ -928,7 +926,7 @@ now brown cow?", '"', true);
|
|||||||
|
|
||||||
var taskVersion = JsonConvert.DeserializeObjectAsync<Version>("'2.0'", new JsonSerializerSettings
|
var taskVersion = JsonConvert.DeserializeObjectAsync<Version>("'2.0'", new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
Converters = {new VersionConverter()}
|
Converters = { new VersionConverter() }
|
||||||
});
|
});
|
||||||
taskVersion.Wait();
|
taskVersion.Wait();
|
||||||
|
|
||||||
|
|||||||
@@ -67,10 +67,7 @@ namespace Newtonsoft.Json.Tests
|
|||||||
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>("Unexpected content while parsing JSON. Path 'u', line 1, position 27.",
|
ExceptionAssert.Throws<JsonReaderException>("Unexpected content while parsing JSON. Path 'u', line 1, position 27.",
|
||||||
() =>
|
() => { reader.Read(); });
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -407,10 +404,7 @@ Nice froob armor.. but ugleh!
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Additional text encountered after finished reading JSON content: c. Path '', line 5, position 2.",
|
"Additional text encountered after finished reading JSON content: c. Path '', line 5, position 2.",
|
||||||
() =>
|
() => { reader.Read(); });
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -661,10 +655,7 @@ Nice froob armor.. but ugleh!
|
|||||||
ExceptionAssert.Throws<ArgumentNullException>(
|
ExceptionAssert.Throws<ArgumentNullException>(
|
||||||
@"Value cannot be null.
|
@"Value cannot be null.
|
||||||
Parameter name: reader",
|
Parameter name: reader",
|
||||||
() =>
|
() => { new JsonTextReader(null); });
|
||||||
{
|
|
||||||
new JsonTextReader(null);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -674,10 +665,7 @@ Parameter name: reader",
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Unterminated string. Expected delimiter: '. Path '', line 1, position 3.",
|
"Unterminated string. Expected delimiter: '. Path '', line 1, position 3.",
|
||||||
() =>
|
() => { reader.Read(); });
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -935,10 +923,7 @@ Parameter name: reader",
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Unexpected end while parsing unicode character. Path '', line 1, position 4.",
|
"Unexpected end while parsing unicode character. Path '', line 1, position 4.",
|
||||||
() =>
|
() => { reader.Read(); });
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -948,10 +933,7 @@ Parameter name: reader",
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Unterminated string. Expected delimiter: '. Path '', line 1, position 3.",
|
"Unterminated string. Expected delimiter: '. Path '', line 1, position 3.",
|
||||||
() =>
|
() => { reader.Read(); });
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -961,10 +943,7 @@ Parameter name: reader",
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Error reading bytes. Unexpected token: Boolean. Path '', line 1, position 4.",
|
"Error reading bytes. Unexpected token: Boolean. Path '', line 1, position 4.",
|
||||||
() =>
|
() => { reader.ReadAsBytes(); });
|
||||||
{
|
|
||||||
reader.ReadAsBytes();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -977,10 +956,7 @@ Parameter name: reader",
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Unterminated string. Expected delimiter: '. Path '', line 1, position 17.",
|
"Unterminated string. Expected delimiter: '. Path '', line 1, position 17.",
|
||||||
() =>
|
() => { reader.ReadAsBytes(); });
|
||||||
{
|
|
||||||
reader.ReadAsBytes();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -1001,10 +977,7 @@ Parameter name: reader",
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Unexpected end while parsing unquoted property name. Path '', line 1, position 4.",
|
"Unexpected end while parsing unquoted property name. Path '', line 1, position 4.",
|
||||||
() =>
|
() => { reader.Read(); });
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -1230,7 +1203,6 @@ bye", reader.Value);
|
|||||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1526,10 +1498,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
@"Invalid character after parsing property name. Expected ':' but got: "". Path 'A', line 3, position 9.",
|
@"Invalid character after parsing property name. Expected ':' but got: "". Path 'A', line 3, position 9.",
|
||||||
() =>
|
() => { reader.Read(); });
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -1641,10 +1610,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Unexpected character encountered while parsing value: }. Path '', line 1, position 1.",
|
"Unexpected character encountered while parsing value: }. Path '', line 1, position 1.",
|
||||||
() =>
|
() => { reader.Read(); });
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -1672,10 +1638,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Unexpected end when reading bytes. Path '', line 1, position 1.",
|
"Unexpected end when reading bytes. Path '', line 1, position 1.",
|
||||||
() =>
|
() => { reader.ReadAsBytes(); });
|
||||||
{
|
|
||||||
reader.ReadAsBytes();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !NET20
|
#if !NET20
|
||||||
@@ -1696,10 +1659,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Error reading decimal. Unexpected token: StartConstructor. Path '', line 1, position 9.",
|
"Error reading decimal. Unexpected token: StartConstructor. Path '', line 1, position 9.",
|
||||||
() =>
|
() => { reader.ReadAsDecimal(); });
|
||||||
{
|
|
||||||
reader.ReadAsDecimal();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -1709,10 +1669,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Error reading bytes. Unexpected token: StartConstructor. Path '', line 1, position 9.",
|
"Error reading bytes. Unexpected token: StartConstructor. Path '', line 1, position 9.",
|
||||||
() =>
|
() => { reader.ReadAsBytes(); });
|
||||||
{
|
|
||||||
reader.ReadAsBytes();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !NET20
|
#if !NET20
|
||||||
@@ -1723,10 +1680,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Error reading date. Unexpected token: StartConstructor. Path '', line 1, position 9.",
|
"Error reading date. Unexpected token: StartConstructor. Path '', line 1, position 9.",
|
||||||
() =>
|
() => { reader.ReadAsDateTimeOffset(); });
|
||||||
{
|
|
||||||
reader.ReadAsDateTimeOffset();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1748,10 +1702,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Unexpected end when reading bytes. Path '[0]', line 1, position 2.",
|
"Unexpected end when reading bytes. Path '[0]', line 1, position 2.",
|
||||||
() =>
|
() => { reader.ReadAsBytes(); });
|
||||||
{
|
|
||||||
reader.ReadAsBytes();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -1761,10 +1712,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Unexpected token when reading bytes: Float. Path '[0]', line 1, position 4.",
|
"Unexpected token when reading bytes: Float. Path '[0]', line 1, position 4.",
|
||||||
() =>
|
() => { reader.ReadAsBytes(); });
|
||||||
{
|
|
||||||
reader.ReadAsBytes();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -1875,10 +1823,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Could not convert string to DateTimeOffset: blablahbla. Path 'Offset', line 1, position 22.",
|
"Could not convert string to DateTimeOffset: blablahbla. Path 'Offset', line 1, position 22.",
|
||||||
() =>
|
() => { reader.ReadAsDateTimeOffset(); });
|
||||||
{
|
|
||||||
reader.ReadAsDateTimeOffset();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -2032,10 +1977,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<FormatException>(
|
ExceptionAssert.Throws<FormatException>(
|
||||||
"Input string was not in a correct format.",
|
"Input string was not in a correct format.",
|
||||||
() =>
|
() => { reader.ReadAsInt32(); });
|
||||||
{
|
|
||||||
reader.ReadAsInt32();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -2045,10 +1987,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Error parsing null value. Path '', line 0, position 0.",
|
"Error parsing null value. Path '', line 0, position 0.",
|
||||||
() =>
|
() => { reader.Read(); });
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -2058,10 +1997,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Error parsing null value. Path '', line 0, position 0.",
|
"Error parsing null value. Path '', line 0, position 0.",
|
||||||
() =>
|
() => { reader.Read(); });
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -2071,10 +2007,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Error parsing null value. Path '', line 1, position 4.",
|
"Error parsing null value. Path '', line 1, position 4.",
|
||||||
() =>
|
() => { reader.Read(); });
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -2084,10 +2017,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Unexpected end while parsing comment. Path '', line 1, position 6.",
|
"Unexpected end while parsing comment. Path '', line 1, position 6.",
|
||||||
() =>
|
() => { reader.Read(); });
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -2097,10 +2027,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Error parsing comment. Expected: *, got s. Path '', line 1, position 1.",
|
"Error parsing comment. Expected: *, got s. Path '', line 1, position 1.",
|
||||||
() =>
|
() => { reader.Read(); });
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -2286,10 +2213,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Unexpected end while parsing constructor. Path '', line 1, position 7.",
|
"Unexpected end while parsing constructor. Path '', line 1, position 7.",
|
||||||
() =>
|
() => { reader.Read(); });
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -2300,10 +2224,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Unexpected character while parsing constructor: !. Path '', line 1, position 9.",
|
"Unexpected character while parsing constructor: !. Path '', line 1, position 9.",
|
||||||
() =>
|
() => { reader.Read(); });
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -2351,10 +2272,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Error parsing boolean value. Path '', line 1, position 4.",
|
"Error parsing boolean value. Path '', line 1, position 4.",
|
||||||
() =>
|
() => { reader.Read(); });
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -2378,10 +2296,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Unexpected character while parsing constructor: ,. Path '', line 1, position 8.",
|
"Unexpected character while parsing constructor: ,. Path '', line 1, position 8.",
|
||||||
() =>
|
() => { Assert.IsTrue(reader.Read()); });
|
||||||
{
|
|
||||||
Assert.IsTrue(reader.Read());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -2426,7 +2341,7 @@ bye", reader.Value);
|
|||||||
string json = @"/*comment*/{/*comment*/Name:/*comment*/true/*comment*/,/*comment*/
|
string json = @"/*comment*/{/*comment*/Name:/*comment*/true/*comment*/,/*comment*/
|
||||||
""ExpiryDate"":/*comment*/new
|
""ExpiryDate"":/*comment*/new
|
||||||
" + StringUtils.LineFeed +
|
" + StringUtils.LineFeed +
|
||||||
@"Date
|
@"Date
|
||||||
(/*comment*/null/*comment*/),
|
(/*comment*/null/*comment*/),
|
||||||
""Price"": 3.99,
|
""Price"": 3.99,
|
||||||
""Sizes"":/*comment*/[/*comment*/
|
""Sizes"":/*comment*/[/*comment*/
|
||||||
@@ -2544,10 +2459,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Additional text encountered after finished reading JSON content: }. Path '', line 1, position 2.",
|
"Additional text encountered after finished reading JSON content: }. Path '', line 1, position 2.",
|
||||||
() =>
|
() => { reader.Read(); });
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -2632,10 +2544,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"The reader's MaxDepth of 1 has been exceeded. Path '[0]', line 1, position 2.",
|
"The reader's MaxDepth of 1 has been exceeded. Path '[0]', line 1, position 2.",
|
||||||
() =>
|
() => { Assert.IsTrue(reader.Read()); });
|
||||||
{
|
|
||||||
Assert.IsTrue(reader.Read());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -2653,10 +2562,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"The reader's MaxDepth of 1 has been exceeded. Path '[0]', line 1, position 2.",
|
"The reader's MaxDepth of 1 has been exceeded. Path '[0]', line 1, position 2.",
|
||||||
() =>
|
() => { Assert.IsTrue(reader.Read()); });
|
||||||
{
|
|
||||||
Assert.IsTrue(reader.Read());
|
|
||||||
});
|
|
||||||
Assert.AreEqual(1, reader.Depth);
|
Assert.AreEqual(1, reader.Depth);
|
||||||
|
|
||||||
Assert.IsTrue(reader.Read());
|
Assert.IsTrue(reader.Read());
|
||||||
@@ -2676,10 +2582,7 @@ bye", reader.Value);
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"The reader's MaxDepth of 1 has been exceeded. Path '[1]', line 1, position 9.",
|
"The reader's MaxDepth of 1 has been exceeded. Path '[1]', line 1, position 9.",
|
||||||
() =>
|
() => { Assert.IsTrue(reader.Read()); });
|
||||||
{
|
|
||||||
Assert.IsTrue(reader.Read());
|
|
||||||
});
|
|
||||||
Assert.AreEqual(1, reader.Depth);
|
Assert.AreEqual(1, reader.Depth);
|
||||||
|
|
||||||
Assert.IsTrue(reader.Read());
|
Assert.IsTrue(reader.Read());
|
||||||
@@ -2928,14 +2831,14 @@ bye", reader.Value);
|
|||||||
|
|
||||||
public class SlowStream : Stream
|
public class SlowStream : Stream
|
||||||
{
|
{
|
||||||
byte[] bytes;
|
private byte[] bytes;
|
||||||
int totalBytesRead;
|
private int totalBytesRead;
|
||||||
int bytesPerRead;
|
private int bytesPerRead;
|
||||||
|
|
||||||
public SlowStream(byte[] content, int bytesPerRead)
|
public SlowStream(byte[] content, int bytesPerRead)
|
||||||
{
|
{
|
||||||
this.bytes = content;
|
bytes = content;
|
||||||
this.totalBytesRead = 0;
|
totalBytesRead = 0;
|
||||||
this.bytesPerRead = bytesPerRead;
|
this.bytesPerRead = bytesPerRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2976,14 +2879,14 @@ bye", reader.Value);
|
|||||||
|
|
||||||
public override int Read(byte[] buffer, int offset, int count)
|
public override int Read(byte[] buffer, int offset, int count)
|
||||||
{
|
{
|
||||||
int toReturn = Math.Min(count, this.bytesPerRead);
|
int toReturn = Math.Min(count, bytesPerRead);
|
||||||
toReturn = Math.Min(toReturn, this.bytes.Length - this.totalBytesRead);
|
toReturn = Math.Min(toReturn, bytes.Length - totalBytesRead);
|
||||||
if (toReturn > 0)
|
if (toReturn > 0)
|
||||||
{
|
{
|
||||||
Array.Copy(this.bytes, this.totalBytesRead, buffer, offset, toReturn);
|
Array.Copy(bytes, totalBytesRead, buffer, offset, toReturn);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.totalBytesRead += toReturn;
|
totalBytesRead += toReturn;
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1194,7 +1194,7 @@ _____'propertyName': NaN
|
|||||||
{
|
{
|
||||||
Console.WriteLine("Started");
|
Console.WriteLine("Started");
|
||||||
|
|
||||||
char c = (char) 0;
|
char c = (char)0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -1212,7 +1212,7 @@ _____'propertyName': NaN
|
|||||||
string oldText = swOld.ToString();
|
string oldText = swOld.ToString();
|
||||||
|
|
||||||
if (newText != oldText)
|
if (newText != oldText)
|
||||||
throw new Exception("Difference for char '{0}' (value {1}). Old text: {2}, New text: {3}".FormatWith(CultureInfo.InvariantCulture, c, (int) c, oldText, newText));
|
throw new Exception("Difference for char '{0}' (value {1}). Old text: {2}, New text: {3}".FormatWith(CultureInfo.InvariantCulture, c, (int)c, oldText, newText));
|
||||||
|
|
||||||
c++;
|
c++;
|
||||||
} while (c != char.MaxValue);
|
} while (c != char.MaxValue);
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ namespace Newtonsoft.Json.Tests
|
|||||||
Assert.IsTrue(reader.Read());
|
Assert.IsTrue(reader.Read());
|
||||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||||
Assert.AreEqual("James", reader.Value.ToString());
|
Assert.AreEqual("James", reader.Value.ToString());
|
||||||
Assert.AreEqual(typeof (string), reader.ValueType);
|
Assert.AreEqual(typeof(string), reader.ValueType);
|
||||||
Assert.AreEqual('"', reader.QuoteChar);
|
Assert.AreEqual('"', reader.QuoteChar);
|
||||||
Assert.AreEqual("name", reader.Path);
|
Assert.AreEqual("name", reader.Path);
|
||||||
|
|
||||||
@@ -1578,10 +1578,7 @@ namespace Newtonsoft.Json.Tests
|
|||||||
IList<ValidationEventArgs> validationEventArgs = new List<ValidationEventArgs>();
|
IList<ValidationEventArgs> validationEventArgs = new List<ValidationEventArgs>();
|
||||||
|
|
||||||
JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(json)));
|
JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(json)));
|
||||||
reader.ValidationEventHandler += (sender, args) =>
|
reader.ValidationEventHandler += (sender, args) => { validationEventArgs.Add(args); };
|
||||||
{
|
|
||||||
validationEventArgs.Add(args);
|
|
||||||
};
|
|
||||||
reader.Schema = JsonSchema.Parse(schema);
|
reader.Schema = JsonSchema.Parse(schema);
|
||||||
|
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
@@ -1594,7 +1591,7 @@ namespace Newtonsoft.Json.Tests
|
|||||||
[Test]
|
[Test]
|
||||||
public void ReadAsBytes()
|
public void ReadAsBytes()
|
||||||
{
|
{
|
||||||
JsonSchema s = new JsonSchemaGenerator().Generate(typeof (byte[]));
|
JsonSchema s = new JsonSchemaGenerator().Generate(typeof(byte[]));
|
||||||
|
|
||||||
byte[] data = Encoding.UTF8.GetBytes("Hello world");
|
byte[] data = Encoding.UTF8.GetBytes("Hello world");
|
||||||
|
|
||||||
@@ -1610,7 +1607,7 @@ namespace Newtonsoft.Json.Tests
|
|||||||
[Test]
|
[Test]
|
||||||
public void ReadAsInt32()
|
public void ReadAsInt32()
|
||||||
{
|
{
|
||||||
JsonSchema s = new JsonSchemaGenerator().Generate(typeof (int));
|
JsonSchema s = new JsonSchemaGenerator().Generate(typeof(int));
|
||||||
|
|
||||||
JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"1")))
|
JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"1")))
|
||||||
{
|
{
|
||||||
@@ -1641,7 +1638,7 @@ namespace Newtonsoft.Json.Tests
|
|||||||
[Test]
|
[Test]
|
||||||
public void ReadAsDecimal()
|
public void ReadAsDecimal()
|
||||||
{
|
{
|
||||||
JsonSchema s = new JsonSchemaGenerator().Generate(typeof (decimal));
|
JsonSchema s = new JsonSchemaGenerator().Generate(typeof(decimal));
|
||||||
|
|
||||||
JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"1.5")))
|
JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"1.5")))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -72,4 +72,5 @@ namespace Newtonsoft.Json.Tests.Linq.ComponentModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -40,7 +40,7 @@ namespace Newtonsoft.Json.Tests.Linq.ComponentModel
|
|||||||
JPropertyDescriptor prop1 = new JPropertyDescriptor("prop1", typeof(string));
|
JPropertyDescriptor prop1 = new JPropertyDescriptor("prop1", typeof(string));
|
||||||
JPropertyDescriptor prop2 = new JPropertyDescriptor("prop2", typeof(JArray));
|
JPropertyDescriptor prop2 = new JPropertyDescriptor("prop2", typeof(JArray));
|
||||||
|
|
||||||
Assert.AreEqual("12345!", ((JValue) prop1.GetValue(o)).Value);
|
Assert.AreEqual("12345!", ((JValue)prop1.GetValue(o)).Value);
|
||||||
Assert.AreEqual(o["prop2"], prop2.GetValue(o));
|
Assert.AreEqual(o["prop2"], prop2.GetValue(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,4 +84,5 @@ namespace Newtonsoft.Json.Tests.Linq.ComponentModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -179,7 +179,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
new JProperty("Guid", new Guid("EA27FE1D-0D80-44F2-BF34-4654156FA7AF")),
|
new JProperty("Guid", new Guid("EA27FE1D-0D80-44F2-BF34-4654156FA7AF")),
|
||||||
new JProperty("TimeSpan", TimeSpan.FromDays(1))
|
new JProperty("TimeSpan", TimeSpan.FromDays(1))
|
||||||
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
||||||
,new JProperty("BigInteger", BigInteger.Parse("1"))
|
, new JProperty("BigInteger", BigInteger.Parse("1"))
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -288,7 +288,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
new JProperty("Guid", new Guid("EA27FE1D-0D80-44F2-BF34-4654156FA7AF")),
|
new JProperty("Guid", new Guid("EA27FE1D-0D80-44F2-BF34-4654156FA7AF")),
|
||||||
new JProperty("TimeSpan", TimeSpan.FromDays(1))
|
new JProperty("TimeSpan", TimeSpan.FromDays(1))
|
||||||
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
||||||
,new JProperty("BigInteger", new BigInteger(100))
|
, new JProperty("BigInteger", new BigInteger(100))
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -622,7 +622,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
new JProperty("Guid", new Guid("EA27FE1D-0D80-44F2-BF34-4654156FA7AF")),
|
new JProperty("Guid", new Guid("EA27FE1D-0D80-44F2-BF34-4654156FA7AF")),
|
||||||
new JProperty("TimeSpan", TimeSpan.FromDays(1))
|
new JProperty("TimeSpan", TimeSpan.FromDays(1))
|
||||||
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
||||||
,new JProperty("BigInteger", new BigInteger(100))
|
, new JProperty("BigInteger", new BigInteger(100))
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -749,7 +749,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
value.Name = "Arine Admin";
|
value.Name = "Arine Admin";
|
||||||
value.Enabled = true;
|
value.Enabled = true;
|
||||||
value.Roles = new[] {"Admin", "User"};
|
value.Roles = new[] { "Admin", "User" };
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(value, Formatting.Indented);
|
string json = JsonConvert.SerializeObject(value, Formatting.Indented);
|
||||||
// {
|
// {
|
||||||
@@ -775,7 +775,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
oldAndBusted["Enabled"] = true;
|
oldAndBusted["Enabled"] = true;
|
||||||
oldAndBusted["Roles"] = new JArray(new[] { "Admin", "User" });
|
oldAndBusted["Roles"] = new JArray(new[] { "Admin", "User" });
|
||||||
|
|
||||||
string oldRole = (string) oldAndBusted["Roles"][0];
|
string oldRole = (string)oldAndBusted["Roles"][0];
|
||||||
// Admin
|
// Admin
|
||||||
|
|
||||||
|
|
||||||
@@ -846,4 +846,5 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -38,6 +38,7 @@ using Newtonsoft.Json.Linq;
|
|||||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||||
#else
|
#else
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Tests.Linq
|
namespace Newtonsoft.Json.Tests.Linq
|
||||||
@@ -50,7 +51,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
{
|
{
|
||||||
JObject o = new JObject
|
JObject o = new JObject
|
||||||
{
|
{
|
||||||
{"results", new JArray(1, 2, 3, 4)}
|
{ "results", new JArray(1, 2, 3, 4) }
|
||||||
};
|
};
|
||||||
|
|
||||||
JArray a = (JArray)o["results"];
|
JArray a = (JArray)o["results"];
|
||||||
@@ -68,7 +69,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
[Test]
|
[Test]
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
JArray a = new JArray {1};
|
JArray a = new JArray { 1 };
|
||||||
Assert.AreEqual(1, a.Count);
|
Assert.AreEqual(1, a.Count);
|
||||||
|
|
||||||
a.Clear();
|
a.Clear();
|
||||||
@@ -89,7 +90,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
{
|
{
|
||||||
JValue v = new JValue(1);
|
JValue v = new JValue(1);
|
||||||
|
|
||||||
JArray a = new JArray {v};
|
JArray a = new JArray { v };
|
||||||
|
|
||||||
Assert.AreEqual(false, a.Contains(new JValue(2)));
|
Assert.AreEqual(false, a.Contains(new JValue(2)));
|
||||||
Assert.AreEqual(false, a.Contains(new JValue(1)));
|
Assert.AreEqual(false, a.Contains(new JValue(1)));
|
||||||
@@ -108,18 +109,17 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
JToken[] a = new JToken[5];
|
JToken[] a = new JToken[5];
|
||||||
|
|
||||||
((ICollection<JToken>) j).CopyTo(a, 1);
|
((ICollection<JToken>)j).CopyTo(a, 1);
|
||||||
|
|
||||||
Assert.AreEqual(null, a[0]);
|
Assert.AreEqual(null, a[0]);
|
||||||
|
|
||||||
Assert.AreEqual(1, (int) a[1]);
|
Assert.AreEqual(1, (int)a[1]);
|
||||||
|
|
||||||
Assert.AreEqual(2, (int) a[2]);
|
Assert.AreEqual(2, (int)a[2]);
|
||||||
|
|
||||||
Assert.AreEqual(3, (int) a[3]);
|
Assert.AreEqual(3, (int)a[3]);
|
||||||
|
|
||||||
Assert.AreEqual(null, a[4]);
|
Assert.AreEqual(null, a[4]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -130,10 +130,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
ExceptionAssert.Throws<ArgumentNullException>(
|
ExceptionAssert.Throws<ArgumentNullException>(
|
||||||
@"Value cannot be null.
|
@"Value cannot be null.
|
||||||
Parameter name: array",
|
Parameter name: array",
|
||||||
() =>
|
() => { ((ICollection<JToken>)j).CopyTo(null, 0); });
|
||||||
{
|
|
||||||
((ICollection<JToken>) j).CopyTo(null, 0);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -144,10 +141,7 @@ Parameter name: array",
|
|||||||
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
|
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
|
||||||
@"arrayIndex is less than 0.
|
@"arrayIndex is less than 0.
|
||||||
Parameter name: arrayIndex",
|
Parameter name: arrayIndex",
|
||||||
() =>
|
() => { ((ICollection<JToken>)j).CopyTo(new JToken[1], -1); });
|
||||||
{
|
|
||||||
((ICollection<JToken>) j).CopyTo(new JToken[1], -1);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -157,10 +151,7 @@ Parameter name: arrayIndex",
|
|||||||
|
|
||||||
ExceptionAssert.Throws<ArgumentException>(
|
ExceptionAssert.Throws<ArgumentException>(
|
||||||
@"arrayIndex is equal to or greater than the length of array.",
|
@"arrayIndex is equal to or greater than the length of array.",
|
||||||
() =>
|
() => { ((ICollection<JToken>)j).CopyTo(new JToken[1], 1); });
|
||||||
{
|
|
||||||
((ICollection<JToken>) j).CopyTo(new JToken[1], 1);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -173,10 +164,7 @@ Parameter name: arrayIndex",
|
|||||||
|
|
||||||
ExceptionAssert.Throws<ArgumentException>(
|
ExceptionAssert.Throws<ArgumentException>(
|
||||||
@"The number of elements in the source JObject is greater than the available space from arrayIndex to the end of the destination array.",
|
@"The number of elements in the source JObject is greater than the available space from arrayIndex to the end of the destination array.",
|
||||||
() =>
|
() => { ((ICollection<JToken>)j).CopyTo(new JToken[3], 1); });
|
||||||
{
|
|
||||||
((ICollection<JToken>)j).CopyTo(new JToken[3], 1);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -255,10 +243,7 @@ Parameter name: arrayIndex",
|
|||||||
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
|
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
|
||||||
@"Index is equal to or greater than Count.
|
@"Index is equal to or greater than Count.
|
||||||
Parameter name: index",
|
Parameter name: index",
|
||||||
() =>
|
() => { j.RemoveAt(0); });
|
||||||
{
|
|
||||||
j.RemoveAt(0);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -269,10 +254,7 @@ Parameter name: index",
|
|||||||
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
|
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
|
||||||
@"Index is less than 0.
|
@"Index is less than 0.
|
||||||
Parameter name: index",
|
Parameter name: index",
|
||||||
() =>
|
() => { j.RemoveAt(-1); });
|
||||||
{
|
|
||||||
j.RemoveAt(-1);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -342,7 +324,7 @@ Parameter name: index",
|
|||||||
JArray j = new JArray();
|
JArray j = new JArray();
|
||||||
j.Insert(0, null);
|
j.Insert(0, null);
|
||||||
|
|
||||||
Assert.AreEqual(null, ((JValue) j[0]).Value);
|
Assert.AreEqual(null, ((JValue)j[0]).Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -353,10 +335,7 @@ Parameter name: index",
|
|||||||
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
|
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
|
||||||
@"Index was out of range. Must be non-negative and less than the size of the collection.
|
@"Index was out of range. Must be non-negative and less than the size of the collection.
|
||||||
Parameter name: index",
|
Parameter name: index",
|
||||||
() =>
|
() => { j.Insert(-1, new JValue(1)); });
|
||||||
{
|
|
||||||
j.Insert(-1, new JValue(1));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -367,10 +346,7 @@ Parameter name: index",
|
|||||||
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
|
ExceptionAssert.Throws<ArgumentOutOfRangeException>(
|
||||||
@"Index must be within the bounds of the List.
|
@"Index must be within the bounds of the List.
|
||||||
Parameter name: index",
|
Parameter name: index",
|
||||||
() =>
|
() => { j.Insert(2, new JValue(1)); });
|
||||||
{
|
|
||||||
j.Insert(2, new JValue(1));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -402,10 +378,7 @@ Parameter name: index",
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path '', line 1, position 1.",
|
"Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path '', line 1, position 1.",
|
||||||
() =>
|
() => { JArray.Parse(json); });
|
||||||
{
|
|
||||||
JArray.Parse(json);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ListItemFields
|
public class ListItemFields
|
||||||
@@ -421,9 +394,9 @@ Parameter name: index",
|
|||||||
|
|
||||||
IEnumerable<ListItemFields> t = new List<ListItemFields>
|
IEnumerable<ListItemFields> t = new List<ListItemFields>
|
||||||
{
|
{
|
||||||
new ListItemFields {ListItemText = "First", ListItemValue = 1},
|
new ListItemFields { ListItemText = "First", ListItemValue = 1 },
|
||||||
new ListItemFields {ListItemText = "Second", ListItemValue = 2},
|
new ListItemFields { ListItemText = "Second", ListItemValue = 2 },
|
||||||
new ListItemFields {ListItemText = "Third", ListItemValue = 3}
|
new ListItemFields { ListItemText = "Third", ListItemValue = 3 }
|
||||||
};
|
};
|
||||||
|
|
||||||
JObject optionValues =
|
JObject optionValues =
|
||||||
@@ -471,7 +444,7 @@ Parameter name: index",
|
|||||||
int i = 1;
|
int i = 1;
|
||||||
foreach (JToken token in a)
|
foreach (JToken token in a)
|
||||||
{
|
{
|
||||||
Assert.AreEqual(i, (int) token);
|
Assert.AreEqual(i, (int)token);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -500,8 +473,8 @@ Parameter name: index",
|
|||||||
a.Add(a);
|
a.Add(a);
|
||||||
|
|
||||||
Assert.AreEqual(3, a.Count);
|
Assert.AreEqual(3, a.Count);
|
||||||
Assert.AreEqual(1, (int) a[0]);
|
Assert.AreEqual(1, (int)a[0]);
|
||||||
Assert.AreEqual(2, (int) a[1]);
|
Assert.AreEqual(2, (int)a[1]);
|
||||||
Assert.AreNotSame(a, a[2]);
|
Assert.AreNotSame(a, a[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -522,24 +495,24 @@ Parameter name: index",
|
|||||||
{
|
{
|
||||||
object key = 0;
|
object key = 0;
|
||||||
|
|
||||||
JArray a = new JArray((object) null);
|
JArray a = new JArray((object)null);
|
||||||
a[key] = new JValue(3);
|
a[key] = new JValue(3);
|
||||||
|
|
||||||
Assert.AreEqual(3, (int) a[key]);
|
Assert.AreEqual(3, (int)a[key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ReplaceAll()
|
public void ReplaceAll()
|
||||||
{
|
{
|
||||||
JArray a = new JArray(new[] {1, 2, 3});
|
JArray a = new JArray(new[] { 1, 2, 3 });
|
||||||
Assert.AreEqual(3, a.Count);
|
Assert.AreEqual(3, a.Count);
|
||||||
Assert.AreEqual(1, (int) a[0]);
|
Assert.AreEqual(1, (int)a[0]);
|
||||||
Assert.AreEqual(2, (int) a[1]);
|
Assert.AreEqual(2, (int)a[1]);
|
||||||
Assert.AreEqual(3, (int) a[2]);
|
Assert.AreEqual(3, (int)a[2]);
|
||||||
|
|
||||||
a.ReplaceAll(1);
|
a.ReplaceAll(1);
|
||||||
Assert.AreEqual(1, a.Count);
|
Assert.AreEqual(1, a.Count);
|
||||||
Assert.AreEqual(1, (int) a[0]);
|
Assert.AreEqual(1, (int)a[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -547,10 +520,7 @@ Parameter name: index",
|
|||||||
{
|
{
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Unexpected end of content while loading JArray. Path '[0]', line 1, position 2.",
|
"Unexpected end of content while loading JArray. Path '[0]', line 1, position 2.",
|
||||||
() =>
|
() => { JArray.Parse("[1"); });
|
||||||
{
|
|
||||||
JArray.Parse("[1");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -561,8 +531,8 @@ Parameter name: index",
|
|||||||
array.Insert(1, 456);
|
array.Insert(1, 456);
|
||||||
|
|
||||||
Assert.AreEqual(2, array.Count);
|
Assert.AreEqual(2, array.Count);
|
||||||
Assert.AreEqual(123, (int) array[0]);
|
Assert.AreEqual(123, (int)array[0]);
|
||||||
Assert.AreEqual(456, (int) array[1]);
|
Assert.AreEqual(456, (int)array[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -576,10 +546,7 @@ Parameter name: index",
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Additional text encountered after finished reading JSON content: ,. Path '', line 5, position 2.",
|
"Additional text encountered after finished reading JSON content: ,. Path '', line 5, position 2.",
|
||||||
() =>
|
() => { JArray.Parse(json); });
|
||||||
{
|
|
||||||
JArray.Parse(json);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ using System.IO;
|
|||||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||||
#else
|
#else
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Tests.Linq
|
namespace Newtonsoft.Json.Tests.Linq
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
public void Keys()
|
public void Keys()
|
||||||
{
|
{
|
||||||
var o = new JObject();
|
var o = new JObject();
|
||||||
var d = (IDictionary<string, JToken>) o;
|
var d = (IDictionary<string, JToken>)o;
|
||||||
|
|
||||||
Assert.AreEqual(0, d.Keys.Count);
|
Assert.AreEqual(0, d.Keys.Count);
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
public void GenericCollectionAdd()
|
public void GenericCollectionAdd()
|
||||||
{
|
{
|
||||||
JObject o = new JObject();
|
JObject o = new JObject();
|
||||||
((ICollection<KeyValuePair<string,JToken>>)o).Add(new KeyValuePair<string,JToken>("PropertyNameValue", new JValue(1)));
|
((ICollection<KeyValuePair<string, JToken>>)o).Add(new KeyValuePair<string, JToken>("PropertyNameValue", new JValue(1)));
|
||||||
|
|
||||||
Assert.AreEqual(1, (int)o["PropertyNameValue"]);
|
Assert.AreEqual(1, (int)o["PropertyNameValue"]);
|
||||||
Assert.AreEqual(1, o.Children().Count());
|
Assert.AreEqual(1, o.Children().Count());
|
||||||
@@ -249,11 +249,11 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
o.Add("PropertyNameValue3", new JValue(3));
|
o.Add("PropertyNameValue3", new JValue(3));
|
||||||
Assert.AreEqual(3, o.Children().Count());
|
Assert.AreEqual(3, o.Children().Count());
|
||||||
|
|
||||||
KeyValuePair<string, JToken>[] a = new KeyValuePair<string,JToken>[5];
|
KeyValuePair<string, JToken>[] a = new KeyValuePair<string, JToken>[5];
|
||||||
|
|
||||||
((ICollection<KeyValuePair<string, JToken>>)o).CopyTo(a, 1);
|
((ICollection<KeyValuePair<string, JToken>>)o).CopyTo(a, 1);
|
||||||
|
|
||||||
Assert.AreEqual(default(KeyValuePair<string,JToken>), a[0]);
|
Assert.AreEqual(default(KeyValuePair<string, JToken>), a[0]);
|
||||||
|
|
||||||
Assert.AreEqual("PropertyNameValue", a[1].Key);
|
Assert.AreEqual("PropertyNameValue", a[1].Key);
|
||||||
Assert.AreEqual(1, (int)a[1].Value);
|
Assert.AreEqual(1, (int)a[1].Value);
|
||||||
@@ -442,13 +442,10 @@ Parameter name: arrayIndex",
|
|||||||
{
|
{
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Invalid property identifier character: ]. Path 'name', line 3, position 5.",
|
"Invalid property identifier character: ]. Path 'name', line 3, position 5.",
|
||||||
() =>
|
() => { JObject.Parse(@"{
|
||||||
{
|
|
||||||
JObject.Parse(@"{
|
|
||||||
""name"": ""James"",
|
""name"": ""James"",
|
||||||
]!#$THIS IS: BAD JSON![{}}}}]
|
]!#$THIS IS: BAD JSON![{}}}}]
|
||||||
}");
|
}"); });
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -699,7 +696,7 @@ Parameter name: arrayIndex",
|
|||||||
JObject o = new JObject();
|
JObject o = new JObject();
|
||||||
o.PropertyChanging += (sender, args) =>
|
o.PropertyChanging += (sender, args) =>
|
||||||
{
|
{
|
||||||
JObject s = (JObject) sender;
|
JObject s = (JObject)sender;
|
||||||
changing = (s[args.PropertyName] != null) ? ((JValue)s[args.PropertyName]).Value : null;
|
changing = (s[args.PropertyName] != null) ? ((JValue)s[args.PropertyName]).Value : null;
|
||||||
changingCount++;
|
changingCount++;
|
||||||
};
|
};
|
||||||
@@ -1382,7 +1379,7 @@ Parameter name: arrayIndex",
|
|||||||
object newObject = l.AddNew();
|
object newObject = l.AddNew();
|
||||||
Assert.IsNotNull(newObject);
|
Assert.IsNotNull(newObject);
|
||||||
|
|
||||||
JProperty p = (JProperty) newObject;
|
JProperty p = (JProperty)newObject;
|
||||||
Assert.AreEqual("Property!", p.Name);
|
Assert.AreEqual("Property!", p.Name);
|
||||||
Assert.AreEqual(o, p.Parent);
|
Assert.AreEqual(o, p.Parent);
|
||||||
}
|
}
|
||||||
@@ -1433,7 +1430,7 @@ Parameter name: arrayIndex",
|
|||||||
|
|
||||||
JProperty p4 = new JProperty("Test4", "IV");
|
JProperty p4 = new JProperty("Test4", "IV");
|
||||||
|
|
||||||
((IList<JToken>) o)[index.Value] = p4;
|
((IList<JToken>)o)[index.Value] = p4;
|
||||||
Assert.AreEqual(changedType, ListChangedType.ItemChanged);
|
Assert.AreEqual(changedType, ListChangedType.ItemChanged);
|
||||||
Assert.AreEqual(index, 2);
|
Assert.AreEqual(index, 2);
|
||||||
Assert.AreEqual(p4, ((IList<JToken>)o)[index.Value]);
|
Assert.AreEqual(p4, ((IList<JToken>)o)[index.Value]);
|
||||||
@@ -1637,10 +1634,7 @@ Parameter name: arrayIndex",
|
|||||||
public void ParseIncomplete()
|
public void ParseIncomplete()
|
||||||
{
|
{
|
||||||
ExceptionAssert.Throws<Exception>("Unexpected end of content while loading JObject. Path 'foo', line 1, position 6.",
|
ExceptionAssert.Throws<Exception>("Unexpected end of content while loading JObject. Path 'foo', line 1, position 6.",
|
||||||
() =>
|
() => { JObject.Parse("{ foo:"); });
|
||||||
{
|
|
||||||
JObject.Parse("{ foo:");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ using Newtonsoft.Json.Linq;
|
|||||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||||
#else
|
#else
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Tests.Linq
|
namespace Newtonsoft.Json.Tests.Linq
|
||||||
@@ -88,10 +89,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
{
|
{
|
||||||
ExceptionAssert.Throws<JsonException>(
|
ExceptionAssert.Throws<JsonException>(
|
||||||
@"Unexpected character while parsing path indexer: [",
|
@"Unexpected character while parsing path indexer: [",
|
||||||
() =>
|
() => { new JPath("Blah[[0]].Two.Three[1].Four"); });
|
||||||
{
|
|
||||||
new JPath("Blah[[0]].Two.Three[1].Four");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -99,10 +97,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
{
|
{
|
||||||
ExceptionAssert.Throws<JsonException>(
|
ExceptionAssert.Throws<JsonException>(
|
||||||
@"Path ended with open indexer. Expected ]",
|
@"Path ended with open indexer. Expected ]",
|
||||||
() =>
|
() => { new JPath("Blah[0"); });
|
||||||
{
|
|
||||||
new JPath("Blah[0");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -131,10 +126,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
{
|
{
|
||||||
ExceptionAssert.Throws<JsonException>(
|
ExceptionAssert.Throws<JsonException>(
|
||||||
"Empty path indexer.",
|
"Empty path indexer.",
|
||||||
() =>
|
() => { new JPath("[]"); });
|
||||||
{
|
|
||||||
new JPath("[]");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -142,10 +134,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
{
|
{
|
||||||
ExceptionAssert.Throws<JsonException>(
|
ExceptionAssert.Throws<JsonException>(
|
||||||
"Unexpected character while parsing path: ]",
|
"Unexpected character while parsing path: ]",
|
||||||
() =>
|
() => { new JPath("]"); });
|
||||||
{
|
|
||||||
new JPath("]");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -164,10 +153,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
{
|
{
|
||||||
ExceptionAssert.Throws<JsonException>(
|
ExceptionAssert.Throws<JsonException>(
|
||||||
"Unexpected character following indexer: B",
|
"Unexpected character following indexer: B",
|
||||||
() =>
|
() => { new JPath("[1]Blah"); });
|
||||||
{
|
|
||||||
new JPath("[1]Blah");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -210,10 +196,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonException>(
|
ExceptionAssert.Throws<JsonException>(
|
||||||
@"Index 1 not valid on JObject.",
|
@"Index 1 not valid on JObject.",
|
||||||
() =>
|
() => { o.SelectToken("[1]", true); });
|
||||||
{
|
|
||||||
o.SelectToken("[1]", true);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -232,10 +215,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonException>(
|
ExceptionAssert.Throws<JsonException>(
|
||||||
@"Property 'BlahBlah' not valid on JArray.",
|
@"Property 'BlahBlah' not valid on JArray.",
|
||||||
() =>
|
() => { a.SelectToken("BlahBlah", true); });
|
||||||
{
|
|
||||||
a.SelectToken("BlahBlah", true);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -245,10 +225,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonException>(
|
ExceptionAssert.Throws<JsonException>(
|
||||||
@"Index 1 outside the bounds of JConstructor.",
|
@"Index 1 outside the bounds of JConstructor.",
|
||||||
() =>
|
() => { c.SelectToken("[1]", true); });
|
||||||
{
|
|
||||||
c.SelectToken("[1]", true);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -259,10 +236,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonException>(
|
ExceptionAssert.Throws<JsonException>(
|
||||||
"Property 'Missing' does not exist on JObject.",
|
"Property 'Missing' does not exist on JObject.",
|
||||||
() =>
|
() => { o.SelectToken("Missing", true); });
|
||||||
{
|
|
||||||
o.SelectToken("Missing", true);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -281,10 +255,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonException>(
|
ExceptionAssert.Throws<JsonException>(
|
||||||
"Index 1000 outside the bounds of JArray.",
|
"Index 1000 outside the bounds of JArray.",
|
||||||
() =>
|
() => { a.SelectToken("[1000].Ha", true); });
|
||||||
{
|
|
||||||
a.SelectToken("[1000].Ha", true);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -302,7 +273,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
public void EvaluateSinglePropertyReturningArray()
|
public void EvaluateSinglePropertyReturningArray()
|
||||||
{
|
{
|
||||||
JObject o = new JObject(
|
JObject o = new JObject(
|
||||||
new JProperty("Blah", new [] { 1, 2, 3 }));
|
new JProperty("Blah", new[] { 1, 2, 3 }));
|
||||||
|
|
||||||
JToken t = o.SelectToken("Blah");
|
JToken t = o.SelectToken("Blah");
|
||||||
Assert.IsNotNull(t);
|
Assert.IsNotNull(t);
|
||||||
|
|||||||
@@ -96,10 +96,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonException>(
|
ExceptionAssert.Throws<JsonException>(
|
||||||
"Cannot add or remove items from Newtonsoft.Json.Linq.JProperty.",
|
"Cannot add or remove items from Newtonsoft.Json.Linq.JProperty.",
|
||||||
() =>
|
() => { l.Clear(); });
|
||||||
{
|
|
||||||
l.Clear();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -110,10 +107,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonException>(
|
ExceptionAssert.Throws<JsonException>(
|
||||||
"Newtonsoft.Json.Linq.JProperty cannot have multiple values.",
|
"Newtonsoft.Json.Linq.JProperty cannot have multiple values.",
|
||||||
() =>
|
() => { l.Add(null); });
|
||||||
{
|
|
||||||
l.Add(null);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -124,10 +118,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonException>(
|
ExceptionAssert.Throws<JsonException>(
|
||||||
"Cannot add or remove items from Newtonsoft.Json.Linq.JProperty.",
|
"Cannot add or remove items from Newtonsoft.Json.Linq.JProperty.",
|
||||||
() =>
|
() => { l.Remove(p.Value); });
|
||||||
{
|
|
||||||
l.Remove(p.Value);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -161,25 +152,22 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
[Test]
|
[Test]
|
||||||
public void MultiContentConstructor()
|
public void MultiContentConstructor()
|
||||||
{
|
{
|
||||||
JProperty p = new JProperty("error", new List<string> {"one", "two"});
|
JProperty p = new JProperty("error", new List<string> { "one", "two" });
|
||||||
JArray a = (JArray) p.Value;
|
JArray a = (JArray)p.Value;
|
||||||
|
|
||||||
Assert.AreEqual(a.Count, 2);
|
Assert.AreEqual(a.Count, 2);
|
||||||
Assert.AreEqual("one", (string) a[0]);
|
Assert.AreEqual("one", (string)a[0]);
|
||||||
Assert.AreEqual("two", (string) a[1]);
|
Assert.AreEqual("two", (string)a[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void IListGenericAdd()
|
public void IListGenericAdd()
|
||||||
{
|
{
|
||||||
IList<JToken> t = new JProperty("error", new List<string> {"one", "two"});
|
IList<JToken> t = new JProperty("error", new List<string> { "one", "two" });
|
||||||
|
|
||||||
ExceptionAssert.Throws<JsonException>(
|
ExceptionAssert.Throws<JsonException>(
|
||||||
"Newtonsoft.Json.Linq.JProperty cannot have multiple values.",
|
"Newtonsoft.Json.Linq.JProperty cannot have multiple values.",
|
||||||
() =>
|
() => { t.Add(1); });
|
||||||
{
|
|
||||||
t.Add(1);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,10 +139,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Could not convert string to DateTimeOffset: blablahbla. Path 'Offset', line 1, position 22.",
|
"Could not convert string to DateTimeOffset: blablahbla. Path 'Offset', line 1, position 22.",
|
||||||
() =>
|
() => { reader.ReadAsDateTimeOffset(); });
|
||||||
{
|
|
||||||
reader.ReadAsDateTimeOffset();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -162,10 +159,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Error reading date. Unexpected token: Boolean. Path 'Offset', line 1, position 14.",
|
"Error reading date. Unexpected token: Boolean. Path 'Offset', line 1, position 14.",
|
||||||
() =>
|
() => { reader.ReadAsDateTimeOffset(); });
|
||||||
{
|
|
||||||
reader.ReadAsDateTimeOffset();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -185,7 +179,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
reader.ReadAsDateTimeOffset();
|
reader.ReadAsDateTimeOffset();
|
||||||
Assert.AreEqual(JsonToken.Date, reader.TokenType);
|
Assert.AreEqual(JsonToken.Date, reader.TokenType);
|
||||||
Assert.AreEqual(typeof (DateTimeOffset), reader.ValueType);
|
Assert.AreEqual(typeof(DateTimeOffset), reader.ValueType);
|
||||||
Assert.AreEqual(new DateTimeOffset(2012, 1, 24, 3, 50, 0, TimeSpan.Zero), reader.Value);
|
Assert.AreEqual(new DateTimeOffset(2012, 1, 24, 3, 50, 0, TimeSpan.Zero), reader.Value);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -497,10 +491,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Could not convert string to integer: hi. Path 'Name', line 1, position 12.",
|
"Could not convert string to integer: hi. Path 'Name', line 1, position 12.",
|
||||||
() =>
|
() => { reader.ReadAsInt32(); });
|
||||||
{
|
|
||||||
reader.ReadAsInt32();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -520,10 +511,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Error reading integer. Unexpected token: Boolean. Path 'Name', line 1, position 12.",
|
"Error reading integer. Unexpected token: Boolean. Path 'Name', line 1, position 12.",
|
||||||
() =>
|
() => { reader.ReadAsInt32(); });
|
||||||
{
|
|
||||||
reader.ReadAsInt32();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -564,10 +552,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Could not convert string to decimal: blah. Path 'Name', line 1, position 14.",
|
"Could not convert string to decimal: blah. Path 'Name', line 1, position 14.",
|
||||||
() =>
|
() => { reader.ReadAsDecimal(); });
|
||||||
{
|
|
||||||
reader.ReadAsDecimal();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -587,10 +572,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
"Error reading decimal. Unexpected token: Boolean. Path 'Name', line 1, position 12.",
|
"Error reading decimal. Unexpected token: Boolean. Path 'Name', line 1, position 12.",
|
||||||
() =>
|
() => { reader.ReadAsDecimal(); });
|
||||||
{
|
|
||||||
reader.ReadAsDecimal();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ using Newtonsoft.Json.Utilities.LinqBridge;
|
|||||||
#else
|
#else
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Newtonsoft.Json.Utilities;
|
using Newtonsoft.Json.Utilities;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Tests.Linq
|
namespace Newtonsoft.Json.Tests.Linq
|
||||||
@@ -377,7 +378,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
Assert.AreEqual(long.MaxValue, (long)(new JValue(new BigInteger(new byte[] { 255, 255, 255, 255, 255, 255, 255, 127 }))));
|
Assert.AreEqual(long.MaxValue, (long)(new JValue(new BigInteger(new byte[] { 255, 255, 255, 255, 255, 255, 255, 127 }))));
|
||||||
Assert.AreEqual("9223372036854775807", (string)(new JValue(new BigInteger(long.MaxValue))));
|
Assert.AreEqual("9223372036854775807", (string)(new JValue(new BigInteger(long.MaxValue))));
|
||||||
|
|
||||||
intData = (byte[]) (new JValue(new BigInteger(long.MaxValue)));
|
intData = (byte[])(new JValue(new BigInteger(long.MaxValue)));
|
||||||
CollectionAssert.AreEqual(new byte[] { 255, 255, 255, 255, 255, 255, 255, 127 }, intData);
|
CollectionAssert.AreEqual(new byte[] { 255, 255, 255, 255, 255, 255, 255, 127 }, intData);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -966,7 +967,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
ICloneable c = a;
|
ICloneable c = a;
|
||||||
|
|
||||||
JArray a2 = (JArray) c.Clone();
|
JArray a2 = (JArray)c.Clone();
|
||||||
|
|
||||||
Assert.IsTrue(a.DeepEquals(a2));
|
Assert.IsTrue(a.DeepEquals(a2));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ using Newtonsoft.Json.Linq;
|
|||||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||||
#else
|
#else
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Tests.Linq
|
namespace Newtonsoft.Json.Tests.Linq
|
||||||
@@ -158,7 +159,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
writer.WriteValue(new BigInteger(123));
|
writer.WriteValue(new BigInteger(123));
|
||||||
writer.WriteEndArray();
|
writer.WriteEndArray();
|
||||||
|
|
||||||
JValue i = (JValue) writer.Token[0];
|
JValue i = (JValue)writer.Token[0];
|
||||||
|
|
||||||
Assert.AreEqual(new BigInteger(123), i.Value);
|
Assert.AreEqual(new BigInteger(123), i.Value);
|
||||||
Assert.AreEqual(JTokenType.Integer, i.Type);
|
Assert.AreEqual(JTokenType.Integer, i.Type);
|
||||||
@@ -214,7 +215,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
|
|
||||||
writer.WriteValue(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Unspecified));
|
writer.WriteValue(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Unspecified));
|
||||||
|
|
||||||
JValue value = (JValue) writer.Token;
|
JValue value = (JValue)writer.Token;
|
||||||
DateTime dt = (DateTime)value.Value;
|
DateTime dt = (DateTime)value.Value;
|
||||||
|
|
||||||
Assert.AreEqual(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Utc), dt);
|
Assert.AreEqual(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Utc), dt);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
[Test]
|
[Test]
|
||||||
public void FloatParseHandling()
|
public void FloatParseHandling()
|
||||||
{
|
{
|
||||||
JValue v = (JValue) JToken.ReadFrom(
|
JValue v = (JValue)JToken.ReadFrom(
|
||||||
new JsonTextReader(new StringReader("9.9"))
|
new JsonTextReader(new StringReader("9.9"))
|
||||||
{
|
{
|
||||||
FloatParseHandling = Json.FloatParseHandling.Decimal
|
FloatParseHandling = Json.FloatParseHandling.Decimal
|
||||||
@@ -103,7 +103,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
Assert.AreEqual(null, v.Value);
|
Assert.AreEqual(null, v.Value);
|
||||||
Assert.AreEqual(JTokenType.Null, v.Type);
|
Assert.AreEqual(JTokenType.Null, v.Type);
|
||||||
|
|
||||||
v.Value = (int?) null;
|
v.Value = (int?)null;
|
||||||
Assert.AreEqual(null, v.Value);
|
Assert.AreEqual(null, v.Value);
|
||||||
Assert.AreEqual(JTokenType.Null, v.Type);
|
Assert.AreEqual(JTokenType.Null, v.Type);
|
||||||
|
|
||||||
@@ -306,7 +306,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
{
|
{
|
||||||
Assert.IsTrue(JToken.DeepEquals(new JValue(5L), new JValue(5)));
|
Assert.IsTrue(JToken.DeepEquals(new JValue(5L), new JValue(5)));
|
||||||
Assert.IsFalse(JToken.DeepEquals(new JValue(5M), new JValue(5)));
|
Assert.IsFalse(JToken.DeepEquals(new JValue(5M), new JValue(5)));
|
||||||
Assert.IsTrue(JToken.DeepEquals(new JValue((ulong) long.MaxValue), new JValue(long.MaxValue)));
|
Assert.IsTrue(JToken.DeepEquals(new JValue((ulong)long.MaxValue), new JValue(long.MaxValue)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -332,8 +332,8 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
ExceptionAssert.Throws<ArgumentException>("Can not convert Null to Int32.",
|
ExceptionAssert.Throws<ArgumentException>("Can not convert Null to Int32.",
|
||||||
() =>
|
() =>
|
||||||
{
|
{
|
||||||
JValue v = new JValue((object) null);
|
JValue v = new JValue((object)null);
|
||||||
int i = (int) v;
|
int i = (int)v;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,7 +385,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
public decimal Compoundings { get; set; }
|
public decimal Compoundings { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly Rate rate = new Rate {Compoundings = 12.166666666666666666666666667m};
|
private readonly Rate rate = new Rate { Compoundings = 12.166666666666666666666666667m };
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void WriteFullDecimalPrecision()
|
public void WriteFullDecimalPrecision()
|
||||||
@@ -444,7 +444,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
TimeSpan offset = ((DateTimeOffset)d.Value).Offset;
|
TimeSpan offset = ((DateTimeOffset)d.Value).Offset;
|
||||||
Assert.AreEqual(TimeSpan.FromHours(1), offset);
|
Assert.AreEqual(TimeSpan.FromHours(1), offset);
|
||||||
|
|
||||||
DateTimeOffset dateTimeOffset = (DateTimeOffset) d;
|
DateTimeOffset dateTimeOffset = (DateTimeOffset)d;
|
||||||
Assert.AreEqual(TimeSpan.FromHours(1), dateTimeOffset.Offset);
|
Assert.AreEqual(TimeSpan.FromHours(1), dateTimeOffset.Offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -629,7 +629,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
{
|
{
|
||||||
IConvertible v = new JValue(9.0m);
|
IConvertible v = new JValue(9.0m);
|
||||||
|
|
||||||
int i = (int)v.ToType(typeof (int), CultureInfo.InvariantCulture);
|
int i = (int)v.ToType(typeof(int), CultureInfo.InvariantCulture);
|
||||||
Assert.AreEqual(9, i);
|
Assert.AreEqual(9, i);
|
||||||
|
|
||||||
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
||||||
|
|||||||
@@ -483,7 +483,8 @@ keyword such as type of business.""
|
|||||||
|
|
||||||
var categories =
|
var categories =
|
||||||
from c in rss["channel"]["item"].Children()["category"].Values<string>()
|
from c in rss["channel"]["item"].Children()["category"].Values<string>()
|
||||||
group c by c into g
|
group c by c
|
||||||
|
into g
|
||||||
orderby g.Count() descending
|
orderby g.Count() descending
|
||||||
select new { Category = g.Key, Count = g.Count() };
|
select new { Category = g.Key, Count = g.Count() };
|
||||||
|
|
||||||
@@ -612,7 +613,8 @@ keyword such as type of business.""
|
|||||||
[Test]
|
[Test]
|
||||||
public void DateTimeOffset()
|
public void DateTimeOffset()
|
||||||
{
|
{
|
||||||
List<DateTimeOffset> testDates = new List<DateTimeOffset> {
|
List<DateTimeOffset> testDates = new List<DateTimeOffset>
|
||||||
|
{
|
||||||
new DateTimeOffset(new DateTime(100, 1, 1, 1, 1, 1, DateTimeKind.Utc)),
|
new DateTimeOffset(new DateTime(100, 1, 1, 1, 1, 1, DateTimeKind.Utc)),
|
||||||
new DateTimeOffset(2000, 1, 1, 1, 1, 1, TimeSpan.Zero),
|
new DateTimeOffset(2000, 1, 1, 1, 1, 1, TimeSpan.Zero),
|
||||||
new DateTimeOffset(2000, 1, 1, 1, 1, 1, TimeSpan.FromHours(13)),
|
new DateTimeOffset(2000, 1, 1, 1, 1, 1, TimeSpan.FromHours(13)),
|
||||||
@@ -679,7 +681,8 @@ keyword such as type of business.""
|
|||||||
{ "title", "James Newton-King" },
|
{ "title", "James Newton-King" },
|
||||||
{ "link", "http://james.newtonking.com" },
|
{ "link", "http://james.newtonking.com" },
|
||||||
{ "description", "James Newton-King's blog." },
|
{ "description", "James Newton-King's blog." },
|
||||||
{ "item",
|
{
|
||||||
|
"item",
|
||||||
(from p in posts
|
(from p in posts
|
||||||
orderby p.Title
|
orderby p.Title
|
||||||
select new
|
select new
|
||||||
@@ -735,8 +738,8 @@ keyword such as type of business.""
|
|||||||
{
|
{
|
||||||
IEnumerable<JObject> o = new[]
|
IEnumerable<JObject> o = new[]
|
||||||
{
|
{
|
||||||
JObject.FromObject(new {First = 1, Second = 2}),
|
JObject.FromObject(new { First = 1, Second = 2 }),
|
||||||
JObject.FromObject(new {First = 1, Second = 2})
|
JObject.FromObject(new { First = 1, Second = 2 })
|
||||||
};
|
};
|
||||||
|
|
||||||
IJEnumerable<JToken> values = o.Properties();
|
IJEnumerable<JToken> values = o.Properties();
|
||||||
|
|||||||
@@ -50,14 +50,14 @@ namespace Newtonsoft.Json.Tests.LinqToSql
|
|||||||
|
|
||||||
Department department = new Department();
|
Department department = new Department();
|
||||||
department.DepartmentId = new Guid((string)o["DepartmentId"]);
|
department.DepartmentId = new Guid((string)o["DepartmentId"]);
|
||||||
department.Name = new string(((string) o["Name"]).Reverse().ToArray());
|
department.Name = new string(((string)o["Name"]).Reverse().ToArray());
|
||||||
|
|
||||||
return department;
|
return department;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanConvert(Type objectType)
|
public override bool CanConvert(Type objectType)
|
||||||
{
|
{
|
||||||
return (objectType == typeof (Department));
|
return (objectType == typeof(Department));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,20 +34,20 @@ namespace Newtonsoft.Json.Tests.LinqToSql
|
|||||||
{
|
{
|
||||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||||
{
|
{
|
||||||
Guid guid = (Guid) value;
|
Guid guid = (Guid)value;
|
||||||
writer.WriteValue(Convert.ToBase64String(guid.ToByteArray()));
|
writer.WriteValue(Convert.ToBase64String(guid.ToByteArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||||
{
|
{
|
||||||
string encodedData = (string) reader.Value;
|
string encodedData = (string)reader.Value;
|
||||||
byte[] data = Convert.FromBase64String(encodedData);
|
byte[] data = Convert.FromBase64String(encodedData);
|
||||||
return new Guid(data);
|
return new Guid(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanConvert(Type objectType)
|
public override bool CanConvert(Type objectType)
|
||||||
{
|
{
|
||||||
return (objectType == typeof (Guid));
|
return (objectType == typeof(Guid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,6 +39,7 @@ namespace Newtonsoft.Json.Tests.LinqToSql
|
|||||||
{
|
{
|
||||||
[JsonConverter(typeof(GuidByteArrayConverter))]
|
[JsonConverter(typeof(GuidByteArrayConverter))]
|
||||||
public Guid RoleId { get; set; }
|
public Guid RoleId { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public EntitySet<PersonRole> PersonRoles { get; set; }
|
public EntitySet<PersonRole> PersonRoles { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,8 +68,7 @@ namespace Newtonsoft.Json.Tests
|
|||||||
private const int Iterations = 100;
|
private const int Iterations = 100;
|
||||||
//private const int Iterations = 5000;
|
//private const int Iterations = 5000;
|
||||||
|
|
||||||
#region Data
|
#region Data
|
||||||
|
|
||||||
private const string BsonHex =
|
private const string BsonHex =
|
||||||
@"A9-01-00-00-04-73-74-72-69-6E-67-73-00-2B-00-00-00-0A-30-00-02-31-00-19-00-00-00-4D-61-72-6B-75-73-20-65-67-67-65-72-20-5D-3E-3C-5B-2C-20-28-32-6E-64-29-00-0A-32-00-00-03-64-69-63-74-69-6F-6E-61-72-79-00-37-00-00-00-10-56-61-6C-20-26-20-61-73-64-31-00-01-00-00-00-10-56-61-6C-32-20-26-20-61-73-64-31-00-03-00-00-00-10-56-61-6C-33-20-26-20-61-73-64-31-00-04-00-00-00-00-02-4E-61-6D-65-00-05-00-00-00-52-69-63-6B-00-09-4E-6F-77-00-EF-BD-69-EC-25-01-00-00-01-42-69-67-4E-75-6D-62-65-72-00-E7-7B-CC-26-96-C7-1F-42-03-41-64-64-72-65-73-73-31-00-47-00-00-00-02-53-74-72-65-65-74-00-0B-00-00-00-66-66-66-20-53-74-72-65-65-74-00-02-50-68-6F-6E-65-00-0F-00-00-00-28-35-30-33-29-20-38-31-34-2D-36-33-33-35-00-09-45-6E-74-65-72-65-64-00-6F-FF-31-53-26-01-00-00-00-04-41-64-64-72-65-73-73-65-73-00-A2-00-00-00-03-30-00-4B-00-00-00-02-53-74-72-65-65-74-00-0F-00-00-00-1F-61-72-72-61-79-3C-61-64-64-72-65-73-73-00-02-50-68-6F-6E-65-00-0F-00-00-00-28-35-30-33-29-20-38-31-34-2D-36-33-33-35-00-09-45-6E-74-65-72-65-64-00-6F-73-0C-E7-25-01-00-00-00-03-31-00-4C-00-00-00-02-53-74-72-65-65-74-00-10-00-00-00-61-72-72-61-79-20-32-20-61-64-64-72-65-73-73-00-02-50-68-6F-6E-65-00-0F-00-00-00-28-35-30-33-29-20-38-31-34-2D-36-33-33-35-00-09-45-6E-74-65-72-65-64-00-6F-17-E6-E1-25-01-00-00-00-00-00";
|
@"A9-01-00-00-04-73-74-72-69-6E-67-73-00-2B-00-00-00-0A-30-00-02-31-00-19-00-00-00-4D-61-72-6B-75-73-20-65-67-67-65-72-20-5D-3E-3C-5B-2C-20-28-32-6E-64-29-00-0A-32-00-00-03-64-69-63-74-69-6F-6E-61-72-79-00-37-00-00-00-10-56-61-6C-20-26-20-61-73-64-31-00-01-00-00-00-10-56-61-6C-32-20-26-20-61-73-64-31-00-03-00-00-00-10-56-61-6C-33-20-26-20-61-73-64-31-00-04-00-00-00-00-02-4E-61-6D-65-00-05-00-00-00-52-69-63-6B-00-09-4E-6F-77-00-EF-BD-69-EC-25-01-00-00-01-42-69-67-4E-75-6D-62-65-72-00-E7-7B-CC-26-96-C7-1F-42-03-41-64-64-72-65-73-73-31-00-47-00-00-00-02-53-74-72-65-65-74-00-0B-00-00-00-66-66-66-20-53-74-72-65-65-74-00-02-50-68-6F-6E-65-00-0F-00-00-00-28-35-30-33-29-20-38-31-34-2D-36-33-33-35-00-09-45-6E-74-65-72-65-64-00-6F-FF-31-53-26-01-00-00-00-04-41-64-64-72-65-73-73-65-73-00-A2-00-00-00-03-30-00-4B-00-00-00-02-53-74-72-65-65-74-00-0F-00-00-00-1F-61-72-72-61-79-3C-61-64-64-72-65-73-73-00-02-50-68-6F-6E-65-00-0F-00-00-00-28-35-30-33-29-20-38-31-34-2D-36-33-33-35-00-09-45-6E-74-65-72-65-64-00-6F-73-0C-E7-25-01-00-00-00-03-31-00-4C-00-00-00-02-53-74-72-65-65-74-00-10-00-00-00-61-72-72-61-79-20-32-20-61-64-64-72-65-73-73-00-02-50-68-6F-6E-65-00-0F-00-00-00-28-35-30-33-29-20-38-31-34-2D-36-33-33-35-00-09-45-6E-74-65-72-65-64-00-6F-17-E6-E1-25-01-00-00-00-00-00";
|
||||||
|
|
||||||
@@ -100,8 +99,7 @@ namespace Newtonsoft.Json.Tests
|
|||||||
DataContractSerializer,
|
DataContractSerializer,
|
||||||
DataContractJsonSerializer
|
DataContractJsonSerializer
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
#endregion
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void SerializeSimpleObject()
|
public void SerializeSimpleObject()
|
||||||
@@ -254,7 +252,7 @@ namespace Newtonsoft.Json.Tests
|
|||||||
obj["Property5"].Value<Int32>();
|
obj["Property5"].Value<Int32>();
|
||||||
}
|
}
|
||||||
watch.Stop();
|
watch.Stop();
|
||||||
var performance1 = (totalIterations/watch.ElapsedMilliseconds)*1000;
|
var performance1 = (totalIterations / watch.ElapsedMilliseconds) * 1000;
|
||||||
Console.WriteLine("JSON: " + watch.Elapsed.TotalSeconds);
|
Console.WriteLine("JSON: " + watch.Elapsed.TotalSeconds);
|
||||||
|
|
||||||
watch.Reset();
|
watch.Reset();
|
||||||
@@ -288,7 +286,7 @@ namespace Newtonsoft.Json.Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
watch.Stop();
|
watch.Stop();
|
||||||
var performance2 = (totalIterations/watch.ElapsedMilliseconds)*1000;
|
var performance2 = (totalIterations / watch.ElapsedMilliseconds) * 1000;
|
||||||
Console.WriteLine("XML: " + watch.Elapsed.TotalSeconds);
|
Console.WriteLine("XML: " + watch.Elapsed.TotalSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,7 +343,7 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < interations; i++)
|
for (int i = 0; i < interations; i++)
|
||||||
{
|
{
|
||||||
s.ToObject(typeof (string));
|
s.ToObject(typeof(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
@@ -450,8 +448,7 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
Console.WriteLine("BinaryFormatter size: {0} bytes", binaryFormatterBytes.Length);
|
Console.WriteLine("BinaryFormatter size: {0} bytes", binaryFormatterBytes.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Serialize
|
#region Serialize
|
||||||
|
|
||||||
private static readonly byte[] Buffer = new byte[4096];
|
private static readonly byte[] Buffer = new byte[4096];
|
||||||
|
|
||||||
public void BenchmarkSerializeMethod(SerializeMethod method, object value)
|
public void BenchmarkSerializeMethod(SerializeMethod method, object value)
|
||||||
@@ -479,7 +476,7 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
{
|
{
|
||||||
TestClass test = new TestClass();
|
TestClass test = new TestClass();
|
||||||
|
|
||||||
test.dictionary = new Dictionary<string, int> {{"Val & asd1", 1}, {"Val2 & asd1", 3}, {"Val3 & asd1", 4}};
|
test.dictionary = new Dictionary<string, int> { { "Val & asd1", 1 }, { "Val2 & asd1", 3 }, { "Val3 & asd1", 4 } };
|
||||||
|
|
||||||
|
|
||||||
test.Address1.Street = "fff Street";
|
test.Address1.Street = "fff Street";
|
||||||
@@ -487,7 +484,7 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
|
|
||||||
test.BigNumber = 34123123123.121M;
|
test.BigNumber = 34123123123.121M;
|
||||||
test.Now = DateTime.Now.AddHours(1);
|
test.Now = DateTime.Now.AddHours(1);
|
||||||
test.strings = new List<string>() {null, "Markus egger ]><[, (2nd)", null};
|
test.strings = new List<string>() { null, "Markus egger ]><[, (2nd)", null };
|
||||||
|
|
||||||
Address address = new Address();
|
Address address = new Address();
|
||||||
address.Entered = DateTime.Now.AddDays(-1);
|
address.Entered = DateTime.Now.AddDays(-1);
|
||||||
@@ -509,7 +506,7 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
Name = "Simple-1",
|
Name = "Simple-1",
|
||||||
Id = 2311,
|
Id = 2311,
|
||||||
Address = "Planet Earth",
|
Address = "Planet Earth",
|
||||||
Scores = new [] { 82, 96, 49, 40, 38, 38, 78, 96, 2, 39 }
|
Scores = new[] { 82, 96, 49, 40, 38, 38, 78, 96, 2, 39 }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -700,11 +697,9 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
//json = BitConverter.ToString(ms.ToArray(), 0, (int)ms.Position);
|
//json = BitConverter.ToString(ms.ToArray(), 0, (int)ms.Position);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Deserialize
|
#region Deserialize
|
||||||
|
|
||||||
public void BenchmarkDeserializeMethod<T>(SerializeMethod method, object json)
|
public void BenchmarkDeserializeMethod<T>(SerializeMethod method, object json)
|
||||||
{
|
{
|
||||||
Deserialize<T>(method, json);
|
Deserialize<T>(method, json);
|
||||||
@@ -728,7 +723,7 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
|
|
||||||
public T DeserializeJsonNet<T>(string json, bool isoDateTimeConverter)
|
public T DeserializeJsonNet<T>(string json, bool isoDateTimeConverter)
|
||||||
{
|
{
|
||||||
Type type = typeof (T);
|
Type type = typeof(T);
|
||||||
|
|
||||||
JsonSerializer serializer = new JsonSerializer();
|
JsonSerializer serializer = new JsonSerializer();
|
||||||
//serializer.ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace;
|
//serializer.ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace;
|
||||||
@@ -737,7 +732,7 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
if (isoDateTimeConverter)
|
if (isoDateTimeConverter)
|
||||||
serializer.Converters.Add(new IsoDateTimeConverter());
|
serializer.Converters.Add(new IsoDateTimeConverter());
|
||||||
|
|
||||||
var value = (T) serializer.Deserialize(new StringReader(json), type);
|
var value = (T)serializer.Deserialize(new StringReader(json), type);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -751,21 +746,21 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
{
|
{
|
||||||
if (reader.TokenType == JsonToken.PropertyName)
|
if (reader.TokenType == JsonToken.PropertyName)
|
||||||
{
|
{
|
||||||
string propertyName = (string) reader.Value;
|
string propertyName = (string)reader.Value;
|
||||||
switch (propertyName)
|
switch (propertyName)
|
||||||
{
|
{
|
||||||
case "strings":
|
case "strings":
|
||||||
reader.Read();
|
reader.Read();
|
||||||
while (reader.Read() && reader.TokenType != JsonToken.EndArray)
|
while (reader.Read() && reader.TokenType != JsonToken.EndArray)
|
||||||
{
|
{
|
||||||
c.strings.Add((string) reader.Value);
|
c.strings.Add((string)reader.Value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "dictionary":
|
case "dictionary":
|
||||||
reader.Read();
|
reader.Read();
|
||||||
while (reader.Read() && reader.TokenType != JsonToken.EndObject)
|
while (reader.Read() && reader.TokenType != JsonToken.EndObject)
|
||||||
{
|
{
|
||||||
string key = (string) reader.Value;
|
string key = (string)reader.Value;
|
||||||
c.dictionary.Add(key, reader.ReadAsInt32().GetValueOrDefault());
|
c.dictionary.Add(key, reader.ReadAsInt32().GetValueOrDefault());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -808,7 +803,7 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
{
|
{
|
||||||
if (reader.TokenType == JsonToken.PropertyName)
|
if (reader.TokenType == JsonToken.PropertyName)
|
||||||
{
|
{
|
||||||
switch ((string) reader.Value)
|
switch ((string)reader.Value)
|
||||||
{
|
{
|
||||||
case "Street":
|
case "Street":
|
||||||
a.Street = reader.ReadAsString();
|
a.Street = reader.ReadAsString();
|
||||||
@@ -831,14 +826,14 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
|
|
||||||
public T DeserializeJsonNetBinary<T>(byte[] bson)
|
public T DeserializeJsonNetBinary<T>(byte[] bson)
|
||||||
{
|
{
|
||||||
Type type = typeof (T);
|
Type type = typeof(T);
|
||||||
|
|
||||||
JsonSerializer serializer = new JsonSerializer();
|
JsonSerializer serializer = new JsonSerializer();
|
||||||
serializer.ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace;
|
serializer.ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace;
|
||||||
serializer.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore;
|
serializer.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore;
|
||||||
serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||||
|
|
||||||
return (T) serializer.Deserialize(new BsonReader(new MemoryStream(bson)), type);
|
return (T)serializer.Deserialize(new BsonReader(new MemoryStream(bson)), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T DeserializeWebExtensions<T>(string json)
|
public T DeserializeWebExtensions<T>(string json)
|
||||||
@@ -851,11 +846,11 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
public T DeserializeDataContractJson<T>(string json)
|
public T DeserializeDataContractJson<T>(string json)
|
||||||
{
|
{
|
||||||
DataContractJsonSerializer dataContractSerializer
|
DataContractJsonSerializer dataContractSerializer
|
||||||
= new DataContractJsonSerializer(typeof (T));
|
= new DataContractJsonSerializer(typeof(T));
|
||||||
|
|
||||||
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json));
|
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json));
|
||||||
|
|
||||||
return (T) dataContractSerializer.ReadObject(ms);
|
return (T)dataContractSerializer.ReadObject(ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
private T Deserialize<T>(SerializeMethod method, object json)
|
private T Deserialize<T>(SerializeMethod method, object json)
|
||||||
@@ -872,15 +867,15 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
|
|
||||||
return default(T);
|
return default(T);
|
||||||
case SerializeMethod.JsonNetBinary:
|
case SerializeMethod.JsonNetBinary:
|
||||||
return DeserializeJsonNetBinary<T>((byte[]) json);
|
return DeserializeJsonNetBinary<T>((byte[])json);
|
||||||
case SerializeMethod.BinaryFormatter:
|
case SerializeMethod.BinaryFormatter:
|
||||||
return DeserializeBinaryFormatter<T>((byte[]) json);
|
return DeserializeBinaryFormatter<T>((byte[])json);
|
||||||
case SerializeMethod.JavaScriptSerializer:
|
case SerializeMethod.JavaScriptSerializer:
|
||||||
return DeserializeWebExtensions<T>((string) json);
|
return DeserializeWebExtensions<T>((string)json);
|
||||||
case SerializeMethod.DataContractSerializer:
|
case SerializeMethod.DataContractSerializer:
|
||||||
return DeserializeDataContract<T>((string) json);
|
return DeserializeDataContract<T>((string)json);
|
||||||
case SerializeMethod.DataContractJsonSerializer:
|
case SerializeMethod.DataContractJsonSerializer:
|
||||||
return DeserializeDataContractJson<T>((string) json);
|
return DeserializeDataContractJson<T>((string)json);
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException("method");
|
throw new ArgumentOutOfRangeException("method");
|
||||||
}
|
}
|
||||||
@@ -890,20 +885,17 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
{
|
{
|
||||||
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
|
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
|
||||||
|
|
||||||
DataContractSerializer serializer = new DataContractSerializer(typeof (T));
|
DataContractSerializer serializer = new DataContractSerializer(typeof(T));
|
||||||
return (T) serializer.ReadObject(ms);
|
return (T)serializer.ReadObject(ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
private T DeserializeBinaryFormatter<T>(byte[] bytes)
|
private T DeserializeBinaryFormatter<T>(byte[] bytes)
|
||||||
{
|
{
|
||||||
BinaryFormatter formatter = new BinaryFormatter();
|
BinaryFormatter formatter = new BinaryFormatter();
|
||||||
return (T) formatter.Deserialize(new MemoryStream(bytes));
|
return (T)formatter.Deserialize(new MemoryStream(bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void SerializeLargeObject()
|
public void SerializeLargeObject()
|
||||||
{
|
{
|
||||||
@@ -1044,8 +1036,7 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
public int Integer { get; set; }
|
public int Integer { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Classes
|
#region Classes
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public class TestClass
|
public class TestClass
|
||||||
@@ -1087,7 +1078,6 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
private Address _Address1 = new Address();
|
private Address _Address1 = new Address();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public List<Address> Addresses
|
public List<Address> Addresses
|
||||||
{
|
{
|
||||||
@@ -1097,9 +1087,11 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
|
|
||||||
private List<Address> _Addresses = new List<Address>();
|
private List<Address> _Addresses = new List<Address>();
|
||||||
|
|
||||||
[DataMember] public List<string> strings = new List<string>();
|
[DataMember]
|
||||||
|
public List<string> strings = new List<string>();
|
||||||
|
|
||||||
[DataMember] public Dictionary<string, int> dictionary = new Dictionary<string, int>();
|
[DataMember]
|
||||||
|
public Dictionary<string, int> dictionary = new Dictionary<string, int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
@@ -1150,7 +1142,6 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
[DataMember]
|
[DataMember]
|
||||||
public int[] Scores { get; set; }
|
public int[] Scores { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ using System.Security;
|
|||||||
#elif NET40
|
#elif NET40
|
||||||
[assembly: AssemblyTitle("Json.NET Tests .NET 4.0")]
|
[assembly: AssemblyTitle("Json.NET Tests .NET 4.0")]
|
||||||
#else
|
#else
|
||||||
|
|
||||||
[assembly: AssemblyTitle("Json.NET Tests")]
|
[assembly: AssemblyTitle("Json.NET Tests")]
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -60,9 +61,11 @@ using System.Security;
|
|||||||
// Setting ComVisible to false makes the types in this assembly not visible
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
// to COM components. If you need to access a type in this assembly from
|
// to COM components. If you need to access a type in this assembly from
|
||||||
// COM, set the ComVisible attribute to true on that type.
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
|
||||||
[assembly: Guid("0be3d72b-d2ef-409c-985c-d3ede89a25f1")]
|
[assembly: Guid("0be3d72b-d2ef-409c-985c-d3ede89a25f1")]
|
||||||
|
|
||||||
// Version information for an assembly consists of the following four values:
|
// Version information for an assembly consists of the following four values:
|
||||||
@@ -74,5 +77,6 @@ using System.Security;
|
|||||||
//
|
//
|
||||||
// You can specify all the values or you can default the Revision and Build Numbers
|
// You can specify all the values or you can default the Revision and Build Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
|
|
||||||
[assembly: AssemblyVersion("4.5.0.0")]
|
[assembly: AssemblyVersion("4.5.0.0")]
|
||||||
[assembly: AssemblyFileVersion("5.0.8.16617")]
|
[assembly: AssemblyFileVersion("5.0.8.16620")]
|
||||||
@@ -38,6 +38,7 @@ using System.IO;
|
|||||||
using Newtonsoft.Json.Tests.TestObjects;
|
using Newtonsoft.Json.Tests.TestObjects;
|
||||||
#if !(SILVERLIGHT || NETFX_CORE)
|
#if !(SILVERLIGHT || NETFX_CORE)
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Tests.Schema
|
namespace Newtonsoft.Json.Tests.Schema
|
||||||
@@ -169,7 +170,7 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
{
|
{
|
||||||
JsonSchemaGenerator generator = new JsonSchemaGenerator();
|
JsonSchemaGenerator generator = new JsonSchemaGenerator();
|
||||||
generator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseAssemblyQualifiedName;
|
generator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseAssemblyQualifiedName;
|
||||||
JsonSchema typeSchema = generator.Generate(typeof (T));
|
JsonSchema typeSchema = generator.Generate(typeof(T));
|
||||||
string schema = typeSchema.ToString();
|
string schema = typeSchema.ToString();
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(value, Formatting.Indented);
|
string json = JsonConvert.SerializeObject(value, Formatting.Indented);
|
||||||
@@ -177,10 +178,7 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
|
|
||||||
List<string> errors = new List<string>();
|
List<string> errors = new List<string>();
|
||||||
|
|
||||||
token.Validate(typeSchema, (sender, args) =>
|
token.Validate(typeSchema, (sender, args) => { errors.Add(args.Message); });
|
||||||
{
|
|
||||||
errors.Add(args.Message);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (errors.Count > 0)
|
if (errors.Count > 0)
|
||||||
Assert.Fail("Schema generated for type '{0}' is not valid." + Environment.NewLine + string.Join(Environment.NewLine, errors.ToArray()), typeof(T));
|
Assert.Fail("Schema generated for type '{0}' is not valid." + Environment.NewLine + string.Join(Environment.NewLine, errors.ToArray()), typeof(T));
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
|
JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
|
||||||
|
|
||||||
Assert.AreEqual("DefaultPrimitiveType", schema.Description);
|
Assert.AreEqual("DefaultPrimitiveType", schema.Description);
|
||||||
Assert.AreEqual(1.1, (double) schema.Default);
|
Assert.AreEqual(1.1, (double)schema.Default);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -357,8 +357,8 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
Assert.AreEqual(JsonSchemaType.String | JsonSchemaType.Array, schema.Type);
|
Assert.AreEqual(JsonSchemaType.String | JsonSchemaType.Array, schema.Type);
|
||||||
|
|
||||||
Assert.AreEqual(8, schema.Enum.Count);
|
Assert.AreEqual(8, schema.Enum.Count);
|
||||||
Assert.AreEqual("string", (string) schema.Enum[0]);
|
Assert.AreEqual("string", (string)schema.Enum[0]);
|
||||||
Assert.AreEqual("any", (string) schema.Enum[schema.Enum.Count - 1]);
|
Assert.AreEqual("any", (string)schema.Enum[schema.Enum.Count - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|||||||
@@ -42,11 +42,12 @@ using Newtonsoft.Json.Schema;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Extensions=Newtonsoft.Json.Schema.Extensions;
|
using Extensions = Newtonsoft.Json.Schema.Extensions;
|
||||||
#if NET20
|
#if NET20
|
||||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||||
#else
|
#else
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Tests.Schema
|
namespace Newtonsoft.Json.Tests.Schema
|
||||||
@@ -58,7 +59,7 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
public void Generate_GenericDictionary()
|
public void Generate_GenericDictionary()
|
||||||
{
|
{
|
||||||
JsonSchemaGenerator generator = new JsonSchemaGenerator();
|
JsonSchemaGenerator generator = new JsonSchemaGenerator();
|
||||||
JsonSchema schema = generator.Generate(typeof (Dictionary<string, List<string>>));
|
JsonSchema schema = generator.Generate(typeof(Dictionary<string, List<string>>));
|
||||||
|
|
||||||
string json = schema.ToString();
|
string json = schema.ToString();
|
||||||
|
|
||||||
@@ -80,8 +81,8 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
|
|
||||||
Dictionary<string, List<string>> value = new Dictionary<string, List<string>>
|
Dictionary<string, List<string>> value = new Dictionary<string, List<string>>
|
||||||
{
|
{
|
||||||
{"HasValue", new List<string>() { "first", "second", null }},
|
{ "HasValue", new List<string>() { "first", "second", null } },
|
||||||
{"NoValue", null}
|
{ "NoValue", null }
|
||||||
};
|
};
|
||||||
|
|
||||||
string valueJson = JsonConvert.SerializeObject(value, Formatting.Indented);
|
string valueJson = JsonConvert.SerializeObject(value, Formatting.Indented);
|
||||||
@@ -248,7 +249,7 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
Assert.AreEqual(null, schema.Id);
|
Assert.AreEqual(null, schema.Id);
|
||||||
|
|
||||||
generator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseTypeName;
|
generator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseTypeName;
|
||||||
schema = generator.Generate(typeof (Store));
|
schema = generator.Generate(typeof(Store));
|
||||||
Assert.AreEqual(typeof(Store).FullName, schema.Id);
|
Assert.AreEqual(typeof(Store).FullName, schema.Id);
|
||||||
|
|
||||||
generator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseAssemblyQualifiedName;
|
generator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseAssemblyQualifiedName;
|
||||||
@@ -530,7 +531,7 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
};
|
};
|
||||||
generator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseTypeName;
|
generator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseTypeName;
|
||||||
|
|
||||||
JsonSchema schema = generator.Generate(typeof (Version), true);
|
JsonSchema schema = generator.Generate(typeof(Version), true);
|
||||||
|
|
||||||
string json = schema.ToString();
|
string json = schema.ToString();
|
||||||
|
|
||||||
@@ -628,7 +629,7 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
[Test]
|
[Test]
|
||||||
public void CircularCollectionReferences()
|
public void CircularCollectionReferences()
|
||||||
{
|
{
|
||||||
Type type = typeof (Workspace);
|
Type type = typeof(Workspace);
|
||||||
JsonSchemaGenerator jsonSchemaGenerator = new JsonSchemaGenerator();
|
JsonSchemaGenerator jsonSchemaGenerator = new JsonSchemaGenerator();
|
||||||
|
|
||||||
jsonSchemaGenerator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseTypeName;
|
jsonSchemaGenerator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseTypeName;
|
||||||
@@ -781,7 +782,7 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
public String Name;
|
public String Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ControlFlowItem : ControlFlowItemBase//A Job
|
public class ControlFlowItem : ControlFlowItemBase //A Job
|
||||||
{
|
{
|
||||||
public TaskCollection Tasks = new TaskCollection();
|
public TaskCollection Tasks = new TaskCollection();
|
||||||
public ContainerCollection Containers = new ContainerCollection();
|
public ContainerCollection Containers = new ContainerCollection();
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
using Newtonsoft.Json.Schema;
|
using Newtonsoft.Json.Schema;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
using Newtonsoft.Json.Schema;
|
using Newtonsoft.Json.Schema;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
@@ -116,6 +117,5 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
|
|
||||||
Assert.AreEqual(node, node.Items[0]);
|
Assert.AreEqual(node, node.Items[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,12 +70,12 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
JsonSchemaSpecTest jsonSchemaSpecTest = new JsonSchemaSpecTest();
|
JsonSchemaSpecTest jsonSchemaSpecTest = new JsonSchemaSpecTest();
|
||||||
|
|
||||||
jsonSchemaSpecTest.FileName = Path.GetFileName(testFile);
|
jsonSchemaSpecTest.FileName = Path.GetFileName(testFile);
|
||||||
jsonSchemaSpecTest.TestCaseDescription = (string) testCase["description"];
|
jsonSchemaSpecTest.TestCaseDescription = (string)testCase["description"];
|
||||||
jsonSchemaSpecTest.Schema = (JObject) testCase["schema"];
|
jsonSchemaSpecTest.Schema = (JObject)testCase["schema"];
|
||||||
|
|
||||||
jsonSchemaSpecTest.TestDescription = (string) test["description"];
|
jsonSchemaSpecTest.TestDescription = (string)test["description"];
|
||||||
jsonSchemaSpecTest.Data = test["data"];
|
jsonSchemaSpecTest.Data = test["data"];
|
||||||
jsonSchemaSpecTest.IsValid = (bool) test["valid"];
|
jsonSchemaSpecTest.IsValid = (bool)test["valid"];
|
||||||
jsonSchemaSpecTest.TestNumber = specTests.Count + 1;
|
jsonSchemaSpecTest.TestNumber = specTests.Count + 1;
|
||||||
|
|
||||||
specTests.Add(jsonSchemaSpecTest);
|
specTests.Add(jsonSchemaSpecTest);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ using Newtonsoft.Json.Linq;
|
|||||||
using Newtonsoft.Json.Schema;
|
using Newtonsoft.Json.Schema;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
@@ -275,7 +276,6 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}", json);
|
}", json);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -516,7 +516,7 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
{
|
{
|
||||||
JsonSchema schema = new JsonSchema();
|
JsonSchema schema = new JsonSchema();
|
||||||
schema.PositionalItemsValidation = true;
|
schema.PositionalItemsValidation = true;
|
||||||
schema.Items = new List<JsonSchema> { new JsonSchema { Type = JsonSchemaType.String }};
|
schema.Items = new List<JsonSchema> { new JsonSchema { Type = JsonSchemaType.String } };
|
||||||
|
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
JsonTextWriter jsonWriter = new JsonTextWriter(writer);
|
JsonTextWriter jsonWriter = new JsonTextWriter(writer);
|
||||||
|
|||||||
+4
-5
@@ -77,7 +77,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
""BirthDate"": ""2000-11-20T23:55:44Z"",
|
""BirthDate"": ""2000-11-20T23:55:44Z"",
|
||||||
""LastModified"": ""2000-11-20T23:55:44Z""
|
""LastModified"": ""2000-11-20T23:55:44Z""
|
||||||
}", json);
|
}", json);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -93,7 +92,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
serializer.Serialize(writer, ignoreAttributeOnClassTestClass);
|
serializer.Serialize(writer, ignoreAttributeOnClassTestClass);
|
||||||
|
|
||||||
JObject o = (JObject) writer.Token;
|
JObject o = (JObject)writer.Token;
|
||||||
JProperty p = o.Property("theField");
|
JProperty p = o.Property("theField");
|
||||||
|
|
||||||
Assert.IsNotNull(p);
|
Assert.IsNotNull(p);
|
||||||
@@ -144,7 +143,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
ExpiryDate = new DateTime(2010, 12, 20, 18, 1, 0, DateTimeKind.Utc),
|
ExpiryDate = new DateTime(2010, 12, 20, 18, 1, 0, DateTimeKind.Utc),
|
||||||
Name = "Widget",
|
Name = "Widget",
|
||||||
Price = 9.99m,
|
Price = 9.99m,
|
||||||
Sizes = new[] {"Small", "Medium", "Large"}
|
Sizes = new[] { "Small", "Medium", "Large" }
|
||||||
};
|
};
|
||||||
|
|
||||||
string json =
|
string json =
|
||||||
@@ -206,8 +205,8 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
{
|
{
|
||||||
Dictionary<string, string> values = new Dictionary<string, string>
|
Dictionary<string, string> values = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{"First", "Value1!"},
|
{ "First", "Value1!" },
|
||||||
{"Second", "Value2!"}
|
{ "Second", "Value2!" }
|
||||||
};
|
};
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(values, Formatting.Indented,
|
string json = JsonConvert.SerializeObject(values, Formatting.Indented,
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ using System.Reflection;
|
|||||||
using Newtonsoft.Json.Tests.TestObjects;
|
using Newtonsoft.Json.Tests.TestObjects;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
public class DynamicContractResolver : DefaultContractResolver
|
public class DynamicContractResolver : DefaultContractResolver
|
||||||
{
|
{
|
||||||
private readonly char _startingWithChar;
|
private readonly char _startingWithChar;
|
||||||
|
|
||||||
public DynamicContractResolver(char startingWithChar)
|
public DynamicContractResolver(char startingWithChar)
|
||||||
: base(false)
|
: base(false)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -195,6 +195,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
[JsonProperty(PropertyName = "firstName")]
|
[JsonProperty(PropertyName = "firstName")]
|
||||||
public string Firstname { get; set; }
|
public string Firstname { get; set; }
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "lastName")]
|
[JsonProperty(PropertyName = "lastName")]
|
||||||
public string Lastname { get; set; }
|
public string Lastname { get; set; }
|
||||||
|
|
||||||
@@ -360,9 +361,12 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
[DefaultValue(1)]
|
[DefaultValue(1)]
|
||||||
public int IntValue1 { get; set; }
|
public int IntValue1 { get; set; }
|
||||||
|
|
||||||
public int IntValue2 { get; set; }
|
public int IntValue2 { get; set; }
|
||||||
|
|
||||||
[DefaultValue(null)]
|
[DefaultValue(null)]
|
||||||
public int IntValue3 { get; set; }
|
public int IntValue3 { get; set; }
|
||||||
|
|
||||||
public DefaultValueHandlingDeserialize ClassValue { get; set; }
|
public DefaultValueHandlingDeserialize ClassValue { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,6 +384,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
[DefaultValue(1)]
|
[DefaultValue(1)]
|
||||||
public int IntValue1 { get; set; }
|
public int IntValue1 { get; set; }
|
||||||
|
|
||||||
public int IntValue2 { get; set; }
|
public int IntValue2 { get; set; }
|
||||||
public DefaultValueHandlingDeserialize ClassValue { get; set; }
|
public DefaultValueHandlingDeserialize ClassValue { get; set; }
|
||||||
}
|
}
|
||||||
@@ -407,43 +412,61 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
{
|
{
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public Guid Guid { get; set; }
|
public Guid Guid { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public TimeSpan TimeSpan { get; set; }
|
public TimeSpan TimeSpan { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public DateTime DateTime { get; set; }
|
public DateTime DateTime { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public DateTimeOffset DateTimeOffset { get; set; }
|
public DateTimeOffset DateTimeOffset { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public decimal Decimal { get; set; }
|
public decimal Decimal { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public int Integer { get; set; }
|
public int Integer { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public double Double { get; set; }
|
public double Double { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public bool Boolean { get; set; }
|
public bool Boolean { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public DefaultStruct Struct { get; set; }
|
public DefaultStruct Struct { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public StringComparison Enum { get; set; }
|
public StringComparison Enum { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public Guid? NullableGuid { get; set; }
|
public Guid? NullableGuid { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public TimeSpan? NullableTimeSpan { get; set; }
|
public TimeSpan? NullableTimeSpan { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public DateTime? NullableDateTime { get; set; }
|
public DateTime? NullableDateTime { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public DateTimeOffset? NullableDateTimeOffset { get; set; }
|
public DateTimeOffset? NullableDateTimeOffset { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public decimal? NullableDecimal { get; set; }
|
public decimal? NullableDecimal { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public int? NullableInteger { get; set; }
|
public int? NullableInteger { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public double? NullableDouble { get; set; }
|
public double? NullableDouble { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public bool? NullableBoolean { get; set; }
|
public bool? NullableBoolean { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public DefaultStruct? NullableStruct { get; set; }
|
public DefaultStruct? NullableStruct { get; set; }
|
||||||
|
|
||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public StringComparison? NullableEnum { get; set; }
|
public StringComparison? NullableEnum { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ using Newtonsoft.Json.Tests.TestObjects;
|
|||||||
using Newtonsoft.Json.Utilities;
|
using Newtonsoft.Json.Utilities;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
@@ -335,8 +336,10 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
private readonly Dictionary<string, object> _members;
|
private readonly Dictionary<string, object> _members;
|
||||||
|
|
||||||
public int Int;
|
public int Int;
|
||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public bool Explicit;
|
public bool Explicit;
|
||||||
|
|
||||||
public DynamicChildObject ChildObject { get; set; }
|
public DynamicChildObject ChildObject { get; set; }
|
||||||
|
|
||||||
internal Dictionary<string, object> Members
|
internal Dictionary<string, object> Members
|
||||||
@@ -395,4 +398,5 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -32,6 +32,7 @@ using System.Text;
|
|||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
@@ -318,4 +319,5 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -102,42 +102,42 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// #region Array
|
// #region Array
|
||||||
// [Test]
|
// [Test]
|
||||||
// public void SerializeArray()
|
// public void SerializeArray()
|
||||||
// {
|
// {
|
||||||
// ImmutableArray<string> l = ImmutableArray.From(new List<string>
|
// ImmutableArray<string> l = ImmutableArray.From(new List<string>
|
||||||
// {
|
// {
|
||||||
// "One",
|
// "One",
|
||||||
// "II",
|
// "II",
|
||||||
// "3"
|
// "3"
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// string json = JsonConvert.SerializeObject(l, Formatting.Indented);
|
// string json = JsonConvert.SerializeObject(l, Formatting.Indented);
|
||||||
// Assert.AreEqual(@"[
|
// Assert.AreEqual(@"[
|
||||||
// ""One"",
|
// ""One"",
|
||||||
// ""II"",
|
// ""II"",
|
||||||
// ""3""
|
// ""3""
|
||||||
//]", json);
|
//]", json);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// [Test]
|
// [Test]
|
||||||
// public void DeserializeArray()
|
// public void DeserializeArray()
|
||||||
// {
|
// {
|
||||||
// string json = @"[
|
// string json = @"[
|
||||||
// ""One"",
|
// ""One"",
|
||||||
// ""II"",
|
// ""II"",
|
||||||
// ""3""
|
// ""3""
|
||||||
//]";
|
//]";
|
||||||
|
|
||||||
// ImmutableArray<string> l = JsonConvert.DeserializeObject<ImmutableArray<string>>(json);
|
// ImmutableArray<string> l = JsonConvert.DeserializeObject<ImmutableArray<string>>(json);
|
||||||
|
|
||||||
// Assert.AreEqual(3, l.Length);
|
// Assert.AreEqual(3, l.Length);
|
||||||
// Assert.AreEqual("One", l[0]);
|
// Assert.AreEqual("One", l[0]);
|
||||||
// Assert.AreEqual("II", l[1]);
|
// Assert.AreEqual("II", l[1]);
|
||||||
// Assert.AreEqual("3", l[2]);
|
// Assert.AreEqual("3", l[2]);
|
||||||
// }
|
// }
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
#region Queue
|
#region Queue
|
||||||
[Test]
|
[Test]
|
||||||
@@ -345,9 +345,9 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
{
|
{
|
||||||
ImmutableDictionary<int, string> l = ImmutableDictionary.CreateRange(new Dictionary<int, string>
|
ImmutableDictionary<int, string> l = ImmutableDictionary.CreateRange(new Dictionary<int, string>
|
||||||
{
|
{
|
||||||
{1, "One"},
|
{ 1, "One" },
|
||||||
{2, "II"},
|
{ 2, "II" },
|
||||||
{3, "3"}
|
{ 3, "3" }
|
||||||
});
|
});
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(l, Formatting.Indented);
|
string json = JsonConvert.SerializeObject(l, Formatting.Indented);
|
||||||
@@ -399,9 +399,9 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
{
|
{
|
||||||
ImmutableSortedDictionary<int, string> l = ImmutableSortedDictionary.CreateRange(new SortedDictionary<int, string>
|
ImmutableSortedDictionary<int, string> l = ImmutableSortedDictionary.CreateRange(new SortedDictionary<int, string>
|
||||||
{
|
{
|
||||||
{1, "One"},
|
{ 1, "One" },
|
||||||
{2, "II"},
|
{ 2, "II" },
|
||||||
{3, "3"}
|
{ 3, "3" }
|
||||||
});
|
});
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(l, Formatting.Indented);
|
string json = JsonConvert.SerializeObject(l, Formatting.Indented);
|
||||||
@@ -431,4 +431,5 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -49,7 +49,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
};
|
};
|
||||||
|
|
||||||
var resolver = new DefaultContractResolver();
|
var resolver = new DefaultContractResolver();
|
||||||
var contract = (JsonObjectContract) resolver.ResolveContract(value.GetType());
|
var contract = (JsonObjectContract)resolver.ResolveContract(value.GetType());
|
||||||
|
|
||||||
Assert.AreEqual(3, contract.Properties.Count);
|
Assert.AreEqual(3, contract.Properties.Count);
|
||||||
Assert.IsTrue(contract.Properties.Contains("OverriddenProperty"), "Contract is missing property 'OverriddenProperty'");
|
Assert.IsTrue(contract.Properties.Contains("OverriddenProperty"), "Contract is missing property 'OverriddenProperty'");
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -29,6 +29,7 @@ using Newtonsoft.Json.Converters;
|
|||||||
using Newtonsoft.Json.Tests.TestObjects;
|
using Newtonsoft.Json.Tests.TestObjects;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
@@ -64,10 +65,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonSerializationException>(
|
ExceptionAssert.Throws<JsonSerializationException>(
|
||||||
@"Could not find member 'Price' on object of type 'ProductShort'. Path 'Price', line 4, position 11.",
|
@"Could not find member 'Price' on object of type 'ProductShort'. Path 'Price', line 4, position 11.",
|
||||||
() =>
|
() => { ProductShort deserializedProductShort = (ProductShort)JsonConvert.DeserializeObject(output, typeof(ProductShort), new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Error }); });
|
||||||
{
|
|
||||||
ProductShort deserializedProductShort = (ProductShort)JsonConvert.DeserializeObject(output, typeof(ProductShort), new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Error });
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -132,10 +130,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonSerializationException>(
|
ExceptionAssert.Throws<JsonSerializationException>(
|
||||||
"Could not find member 'Missing' on object of type 'DoubleClass'. Path 'Missing', line 1, position 11.",
|
"Could not find member 'Missing' on object of type 'DoubleClass'. Path 'Missing', line 1, position 11.",
|
||||||
() =>
|
() => { JsonConvert.DeserializeObject<DoubleClass>(json, new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Error }); });
|
||||||
{
|
|
||||||
JsonConvert.DeserializeObject<DoubleClass>(json, new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Error });
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ using System.IO;
|
|||||||
using Newtonsoft.Json.Tests.TestObjects;
|
using Newtonsoft.Json.Tests.TestObjects;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ using System.IO;
|
|||||||
using Newtonsoft.Json.Tests.TestObjects;
|
using Newtonsoft.Json.Tests.TestObjects;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
@@ -157,10 +158,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
public void PopulateWithBadJson()
|
public void PopulateWithBadJson()
|
||||||
{
|
{
|
||||||
ExceptionAssert.Throws<JsonSerializationException>("Unexpected initial token 'Integer' when populating object. Expected JSON object or array. Path '', line 1, position 1.",
|
ExceptionAssert.Throws<JsonSerializationException>("Unexpected initial token 'Integer' when populating object. Expected JSON object or array. Path '', line 1, position 1.",
|
||||||
() =>
|
() => { JsonConvert.PopulateObject("1", new Person()); });
|
||||||
{
|
|
||||||
JsonConvert.PopulateObject("1", new Person());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,6 +32,7 @@ using Newtonsoft.Json.Linq;
|
|||||||
using Newtonsoft.Json.Tests.TestObjects;
|
using Newtonsoft.Json.Tests.TestObjects;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
@@ -106,10 +107,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonSerializationException>(
|
ExceptionAssert.Throws<JsonSerializationException>(
|
||||||
"Self referencing loop detected with type '" + classRef + "'. Path '[2][0]'.",
|
"Self referencing loop detected with type '" + classRef + "'. Path '[2][0]'.",
|
||||||
() =>
|
() => { JsonConvert.SerializeObject(circularList, Formatting.Indented); });
|
||||||
{
|
|
||||||
JsonConvert.SerializeObject(circularList, Formatting.Indented);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -261,15 +259,12 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
string classRef = typeof(CircularDictionary).FullName;
|
string classRef = typeof(CircularDictionary).FullName;
|
||||||
|
|
||||||
CircularDictionary circularDictionary = new CircularDictionary();
|
CircularDictionary circularDictionary = new CircularDictionary();
|
||||||
circularDictionary.Add("other", new CircularDictionary {{"blah", null}});
|
circularDictionary.Add("other", new CircularDictionary { { "blah", null } });
|
||||||
circularDictionary.Add("self", circularDictionary);
|
circularDictionary.Add("self", circularDictionary);
|
||||||
|
|
||||||
ExceptionAssert.Throws<JsonSerializationException>(
|
ExceptionAssert.Throws<JsonSerializationException>(
|
||||||
@"Self referencing loop detected with type '" + classRef + "'. Path ''.",
|
@"Self referencing loop detected with type '" + classRef + "'. Path ''.",
|
||||||
() =>
|
() => { JsonConvert.SerializeObject(circularDictionary, Formatting.Indented); });
|
||||||
{
|
|
||||||
JsonConvert.SerializeObject(circularDictionary, Formatting.Indented);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -615,10 +610,10 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
Dictionary<string, EmployeeReference> employees = new Dictionary<string, EmployeeReference>
|
Dictionary<string, EmployeeReference> employees = new Dictionary<string, EmployeeReference>
|
||||||
{
|
{
|
||||||
{"One", e1},
|
{ "One", e1 },
|
||||||
{"Two", e2},
|
{ "Two", e2 },
|
||||||
{"Three", e1},
|
{ "Three", e1 },
|
||||||
{"Four", e2}
|
{ "Four", e2 }
|
||||||
};
|
};
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(employees, Formatting.Indented);
|
string json = JsonConvert.SerializeObject(employees, Formatting.Indented);
|
||||||
@@ -759,7 +754,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
public class User
|
public class User
|
||||||
{
|
{
|
||||||
#region properties
|
#region properties
|
||||||
|
|
||||||
[JsonProperty(Required = Required.Always, PropertyName = "SecretType")]
|
[JsonProperty(Required = Required.Always, PropertyName = "SecretType")]
|
||||||
private string secretType;
|
private string secretType;
|
||||||
|
|
||||||
@@ -774,27 +768,22 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public User Friend { get; set; }
|
public User Friend { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region constructors
|
#region constructors
|
||||||
|
|
||||||
public User()
|
public User()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public User(string login, Type secretType)
|
public User(string login, Type secretType)
|
||||||
: this()
|
: this()
|
||||||
{
|
{
|
||||||
this.Login = login;
|
Login = login;
|
||||||
this.SecretType = secretType;
|
SecretType = secretType;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region methods
|
#region methods
|
||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
{
|
{
|
||||||
return SecretType.GetHashCode();
|
return SecretType.GetHashCode();
|
||||||
@@ -804,7 +793,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
{
|
{
|
||||||
return string.Format("SecretType: {0}, Login: {1}", secretType, Login);
|
return string.Format("SecretType: {0}, Login: {1}", secretType, Login);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1113,8 +1101,10 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
{
|
{
|
||||||
public TestComponentSimple Component1 { get; set; }
|
public TestComponentSimple Component1 { get; set; }
|
||||||
public TestComponentSimple Component2 { get; set; }
|
public TestComponentSimple Component2 { get; set; }
|
||||||
|
|
||||||
[JsonProperty(IsReference = false)]
|
[JsonProperty(IsReference = false)]
|
||||||
public TestComponentSimple ComponentNotReference { get; set; }
|
public TestComponentSimple ComponentNotReference { get; set; }
|
||||||
|
|
||||||
public string String { get; set; }
|
public string String { get; set; }
|
||||||
public int Integer { get; set; }
|
public int Integer { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestCl
|
|||||||
using Test = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute;
|
using Test = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute;
|
||||||
#endif
|
#endif
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using ErrorEventArgs=Newtonsoft.Json.Serialization.ErrorEventArgs;
|
using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs;
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Tests.Serialization
|
namespace Newtonsoft.Json.Tests.Serialization
|
||||||
{
|
{
|
||||||
@@ -273,7 +273,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
errors.Add(args.ErrorContext.Path + " - " + args.ErrorContext.Member + " - " + args.ErrorContext.Error.Message);
|
errors.Add(args.ErrorContext.Path + " - " + args.ErrorContext.Member + " - " + args.ErrorContext.Error.Message);
|
||||||
args.ErrorContext.Handled = true;
|
args.ErrorContext.Handled = true;
|
||||||
},
|
},
|
||||||
Converters = {new IsoDateTimeConverter()}
|
Converters = { new IsoDateTimeConverter() }
|
||||||
});
|
});
|
||||||
var c = serializer.Deserialize<List<DateTime>>(new JsonTextReader(new StringReader(@"[
|
var c = serializer.Deserialize<List<DateTime>>(new JsonTextReader(new StringReader(@"[
|
||||||
""2009-09-09T00:00:00Z"",
|
""2009-09-09T00:00:00Z"",
|
||||||
@@ -388,7 +388,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
errors.Add(args.ErrorContext.Path + " - " + args.ErrorContext.Member + " - " + args.ErrorContext.Error.Message);
|
errors.Add(args.ErrorContext.Path + " - " + args.ErrorContext.Member + " - " + args.ErrorContext.Error.Message);
|
||||||
};
|
};
|
||||||
|
|
||||||
serializer.Deserialize(new StringReader(json), typeof (List<List<DateTime>>));
|
serializer.Deserialize(new StringReader(json), typeof(List<List<DateTime>>));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -412,7 +412,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
errors.Add(args.ErrorContext.Path + " - " + args.ErrorContext.Member + " - " + args.ErrorContext.Error.Message);
|
errors.Add(args.ErrorContext.Path + " - " + args.ErrorContext.Member + " - " + args.ErrorContext.Error.Message);
|
||||||
args.ErrorContext.Handled = true;
|
args.ErrorContext.Handled = true;
|
||||||
};
|
};
|
||||||
serializer.Deserialize(new JsonTextReader(new StringReader(json)), typeof (MyTypeWithRequiredMembers));
|
serializer.Deserialize(new JsonTextReader(new StringReader(json)), typeof(MyTypeWithRequiredMembers));
|
||||||
|
|
||||||
Assert.AreEqual(2, errors.Count);
|
Assert.AreEqual(2, errors.Count);
|
||||||
Assert.AreEqual(" - Required1 - Required property 'Required1' not found in JSON. Path '', line 1, position 2.", errors[0]);
|
Assert.AreEqual(" - Required1 - Required property 'Required1' not found in JSON. Path '', line 1, position 2.", errors[0]);
|
||||||
@@ -433,7 +433,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
args.ErrorContext.Handled = true;
|
args.ErrorContext.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
serializer.Deserialize(new JsonTextReader(new StringReader(json)), typeof (int[]));
|
serializer.Deserialize(new JsonTextReader(new StringReader(json)), typeof(int[]));
|
||||||
|
|
||||||
Assert.AreEqual(2, errors.Count);
|
Assert.AreEqual(2, errors.Count);
|
||||||
Assert.AreEqual("[0] - 0 - Could not convert string to integer: a. Path '[0]', line 1, position 4.", errors[0]);
|
Assert.AreEqual("[0] - 0 - Could not convert string to integer: a. Path '[0]', line 1, position 4.", errors[0]);
|
||||||
@@ -454,7 +454,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
args.ErrorContext.Handled = true;
|
args.ErrorContext.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
serializer.Deserialize(new JsonTextReader(new StringReader(json)), typeof (int[,]));
|
serializer.Deserialize(new JsonTextReader(new StringReader(json)), typeof(int[,]));
|
||||||
|
|
||||||
Assert.AreEqual(2, errors.Count);
|
Assert.AreEqual(2, errors.Count);
|
||||||
Assert.AreEqual("[0][0] - 0 - Could not convert string to integer: a. Path '[0][0]', line 1, position 5.", errors[0]);
|
Assert.AreEqual("[0][0] - 0 - Could not convert string to integer: a. Path '[0][0]', line 1, position 5.", errors[0]);
|
||||||
@@ -465,7 +465,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
public void ErrorHandlingAndAvoidingRecursiveDepthError()
|
public void ErrorHandlingAndAvoidingRecursiveDepthError()
|
||||||
{
|
{
|
||||||
string json = "{'A':{'A':{'A':{'A':{'A':{}}}}}}";
|
string json = "{'A':{'A':{'A':{'A':{'A':{}}}}}}";
|
||||||
JsonSerializer serializer = new JsonSerializer() {};
|
JsonSerializer serializer = new JsonSerializer() { };
|
||||||
IList<string> errors = new List<string>();
|
IList<string> errors = new List<string>();
|
||||||
serializer.Error += (sender, e) =>
|
serializer.Error += (sender, e) =>
|
||||||
{
|
{
|
||||||
@@ -473,7 +473,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
errors.Add(e.ErrorContext.Path);
|
errors.Add(e.ErrorContext.Path);
|
||||||
};
|
};
|
||||||
|
|
||||||
serializer.Deserialize<Nest>(new JsonTextReader(new StringReader(json)) {MaxDepth = 3});
|
serializer.Deserialize<Nest>(new JsonTextReader(new StringReader(json)) { MaxDepth = 3 });
|
||||||
|
|
||||||
Assert.AreEqual(1, errors.Count);
|
Assert.AreEqual(1, errors.Count);
|
||||||
Assert.AreEqual("A.A.A", errors[0]);
|
Assert.AreEqual("A.A.A", errors[0]);
|
||||||
@@ -512,7 +512,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
object o = JsonConvert.DeserializeObject(
|
object o = JsonConvert.DeserializeObject(
|
||||||
"[0,x]",
|
"[0,x]",
|
||||||
typeof (int[]),
|
typeof(int[]),
|
||||||
new JsonSerializerSettings
|
new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
Error = (sender, arg) =>
|
Error = (sender, arg) =>
|
||||||
@@ -563,9 +563,9 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
const string input = "{\"events\":[{\"code\":64411},{\"code\":64411,\"prio";
|
const string input = "{\"events\":[{\"code\":64411},{\"code\":64411,\"prio";
|
||||||
|
|
||||||
const int maxDepth = 256;
|
const int maxDepth = 256;
|
||||||
using (var jsonTextReader = new JsonTextReader(new StringReader(input)) {MaxDepth = maxDepth})
|
using (var jsonTextReader = new JsonTextReader(new StringReader(input)) { MaxDepth = maxDepth })
|
||||||
{
|
{
|
||||||
JsonSerializer jsonSerializer = JsonSerializer.Create(new JsonSerializerSettings {MaxDepth = maxDepth});
|
JsonSerializer jsonSerializer = JsonSerializer.Create(new JsonSerializerSettings { MaxDepth = maxDepth });
|
||||||
jsonSerializer.Error += (sender, e) =>
|
jsonSerializer.Error += (sender, e) =>
|
||||||
{
|
{
|
||||||
errors.Add(e.ErrorContext.Error.Message);
|
errors.Add(e.ErrorContext.Error.Message);
|
||||||
@@ -593,9 +593,9 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
const string input = "{\"events\":{\"code\":64411},\"events2\":{\"code\":64412,";
|
const string input = "{\"events\":{\"code\":64411},\"events2\":{\"code\":64412,";
|
||||||
|
|
||||||
const int maxDepth = 256;
|
const int maxDepth = 256;
|
||||||
using (var jsonTextReader = new JsonTextReader(new StringReader(input)) {MaxDepth = maxDepth})
|
using (var jsonTextReader = new JsonTextReader(new StringReader(input)) { MaxDepth = maxDepth })
|
||||||
{
|
{
|
||||||
JsonSerializer jsonSerializer = JsonSerializer.Create(new JsonSerializerSettings {MaxDepth = maxDepth});
|
JsonSerializer jsonSerializer = JsonSerializer.Create(new JsonSerializerSettings { MaxDepth = maxDepth });
|
||||||
jsonSerializer.Error += (sender, e) =>
|
jsonSerializer.Error += (sender, e) =>
|
||||||
{
|
{
|
||||||
errors.Add(e.ErrorContext.Error.Message);
|
errors.Add(e.ErrorContext.Error.Message);
|
||||||
@@ -654,16 +654,13 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
public void WriteEndOnPropertyState()
|
public void WriteEndOnPropertyState()
|
||||||
{
|
{
|
||||||
JsonSerializerSettings settings = new JsonSerializerSettings();
|
JsonSerializerSettings settings = new JsonSerializerSettings();
|
||||||
settings.Error += (obj, args) =>
|
settings.Error += (obj, args) => { args.ErrorContext.Handled = true; };
|
||||||
{
|
|
||||||
args.ErrorContext.Handled = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
var data = new List<ErrorPerson2>()
|
var data = new List<ErrorPerson2>()
|
||||||
{
|
{
|
||||||
new ErrorPerson2 {FirstName = "Scott", LastName = "Hanselman"},
|
new ErrorPerson2 { FirstName = "Scott", LastName = "Hanselman" },
|
||||||
new ErrorPerson2 {FirstName = "Scott", LastName = "Hunter"},
|
new ErrorPerson2 { FirstName = "Scott", LastName = "Hunter" },
|
||||||
new ErrorPerson2 {FirstName = "Scott", LastName = "Guthrie"},
|
new ErrorPerson2 { FirstName = "Scott", LastName = "Guthrie" },
|
||||||
};
|
};
|
||||||
|
|
||||||
Dictionary<string, IEnumerable<IErrorPerson2>> dictionary = data.GroupBy(person => person.FirstName).ToDictionary(group => @group.Key, group => @group.Cast<IErrorPerson2>());
|
Dictionary<string, IEnumerable<IErrorPerson2>> dictionary = data.GroupBy(person => person.FirstName).ToDictionary(group => @group.Key, group => @group.Cast<IErrorPerson2>());
|
||||||
@@ -675,17 +672,14 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
public void WriteEndOnPropertyState2()
|
public void WriteEndOnPropertyState2()
|
||||||
{
|
{
|
||||||
JsonSerializerSettings settings = new JsonSerializerSettings();
|
JsonSerializerSettings settings = new JsonSerializerSettings();
|
||||||
settings.Error += (obj, args) =>
|
settings.Error += (obj, args) => { args.ErrorContext.Handled = true; };
|
||||||
{
|
|
||||||
args.ErrorContext.Handled = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
var data = new List<ErrorPerson2>
|
var data = new List<ErrorPerson2>
|
||||||
{
|
{
|
||||||
new ErrorPerson2 {FirstName = "Scott", LastName = "Hanselman"},
|
new ErrorPerson2 { FirstName = "Scott", LastName = "Hanselman" },
|
||||||
new ErrorPerson2 {FirstName = "Scott", LastName = "Hunter"},
|
new ErrorPerson2 { FirstName = "Scott", LastName = "Hunter" },
|
||||||
new ErrorPerson2 {FirstName = "Scott", LastName = "Guthrie"},
|
new ErrorPerson2 { FirstName = "Scott", LastName = "Guthrie" },
|
||||||
new ErrorPerson2 {FirstName = "James", LastName = "Newton-King"},
|
new ErrorPerson2 { FirstName = "James", LastName = "Newton-King" },
|
||||||
};
|
};
|
||||||
|
|
||||||
Dictionary<string, IEnumerable<IErrorPerson2>> dictionary = data.GroupBy(person => person.FirstName).ToDictionary(group => @group.Key, group => @group.Cast<IErrorPerson2>());
|
Dictionary<string, IEnumerable<IErrorPerson2>> dictionary = data.GroupBy(person => person.FirstName).ToDictionary(group => @group.Key, group => @group.Cast<IErrorPerson2>());
|
||||||
@@ -702,10 +696,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
MemoryStream stream = new MemoryStream(byteArray);
|
MemoryStream stream = new MemoryStream(byteArray);
|
||||||
JsonTextReader jReader = new JsonTextReader(new StreamReader(stream));
|
JsonTextReader jReader = new JsonTextReader(new StreamReader(stream));
|
||||||
JsonSerializer s = new JsonSerializer();
|
JsonSerializer s = new JsonSerializer();
|
||||||
s.Error += (sender, args) =>
|
s.Error += (sender, args) => { args.ErrorContext.Handled = true; };
|
||||||
{
|
|
||||||
args.ErrorContext.Handled = true;
|
|
||||||
};
|
|
||||||
ErrorPerson2 obj = s.Deserialize<ErrorPerson2>(jReader);
|
ErrorPerson2 obj = s.Deserialize<ErrorPerson2>(jReader);
|
||||||
|
|
||||||
Assert.IsNull(obj);
|
Assert.IsNull(obj);
|
||||||
@@ -722,19 +713,15 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
ExceptionAssert.Throws<JsonReaderException>(
|
ExceptionAssert.Throws<JsonReaderException>(
|
||||||
@"Unterminated string. Expected delimiter: "". Path '', line 1, position 3.",
|
@"Unterminated string. Expected delimiter: "". Path '', line 1, position 3.",
|
||||||
() =>
|
() => { ErrorTestObject obj = s.Deserialize<ErrorTestObject>(jReader); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal interface IErrorPerson2
|
||||||
{
|
{
|
||||||
ErrorTestObject obj = s.Deserialize<ErrorTestObject>(jReader);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IErrorPerson2
|
internal class ErrorPerson2 //:IPerson - oops! Forgot to implement the person interface
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class ErrorPerson2//:IPerson - oops! Forgot to implement the person interface
|
|
||||||
{
|
{
|
||||||
public string LastName { get; set; }
|
public string LastName { get; set; }
|
||||||
public string FirstName { get; set; }
|
public string FirstName { get; set; }
|
||||||
@@ -799,8 +786,11 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
[JsonObject]
|
[JsonObject]
|
||||||
public class MyTypeWithRequiredMembers
|
public class MyTypeWithRequiredMembers
|
||||||
{
|
{
|
||||||
[JsonProperty(Required = Required.AllowNull)] public string Required1;
|
[JsonProperty(Required = Required.AllowNull)]
|
||||||
[JsonProperty(Required = Required.AllowNull)] public string Required2;
|
public string Required1;
|
||||||
|
|
||||||
|
[JsonProperty(Required = Required.AllowNull)]
|
||||||
|
public string Required2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LogMessage
|
public class LogMessage
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
[Test]
|
[Test]
|
||||||
public void ObjectEvents()
|
public void ObjectEvents()
|
||||||
{
|
{
|
||||||
SerializationEventTestObject[] objs = new[] {new SerializationEventTestObject(), new DerivedSerializationEventTestObject()};
|
SerializationEventTestObject[] objs = new[] { new SerializationEventTestObject(), new DerivedSerializationEventTestObject() };
|
||||||
|
|
||||||
foreach (SerializationEventTestObject current in objs)
|
foreach (SerializationEventTestObject current in objs)
|
||||||
{
|
{
|
||||||
@@ -89,7 +89,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
}");
|
}");
|
||||||
o["Member6"] = "Dummy text for error";
|
o["Member6"] = "Dummy text for error";
|
||||||
|
|
||||||
obj = (SerializationEventTestObject) JsonConvert.DeserializeObject(o.ToString(), obj.GetType());
|
obj = (SerializationEventTestObject)JsonConvert.DeserializeObject(o.ToString(), obj.GetType());
|
||||||
|
|
||||||
Assert.AreEqual(11, obj.Member1);
|
Assert.AreEqual(11, obj.Member1);
|
||||||
Assert.AreEqual("This value went into the data file during serialization.", obj.Member2);
|
Assert.AreEqual("This value went into the data file during serialization.", obj.Member2);
|
||||||
@@ -338,6 +338,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
Debug.Assert(foo.Identifier == 25);
|
Debug.Assert(foo.Identifier == 25);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public class FooEvent
|
public class FooEvent
|
||||||
{
|
{
|
||||||
public int Identifier { get; set; }
|
public int Identifier { get; set; }
|
||||||
@@ -345,7 +346,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
[OnError]
|
[OnError]
|
||||||
private void OnError(StreamingContext context, ErrorContext error)
|
private void OnError(StreamingContext context, ErrorContext error)
|
||||||
{
|
{
|
||||||
this.Identifier = 25;
|
Identifier = 25;
|
||||||
|
|
||||||
// Here we could for example manually copy the
|
// Here we could for example manually copy the
|
||||||
// persisted "Id" value into the renamed "Identifier"
|
// persisted "Id" value into the renamed "Identifier"
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ using Newtonsoft.Json.Tests.TestObjects;
|
|||||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||||
#else
|
#else
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Tests.Serialization
|
namespace Newtonsoft.Json.Tests.Serialization
|
||||||
@@ -75,14 +76,14 @@ Newtonsoft.Json Error: 0 : Error!
|
|||||||
{
|
{
|
||||||
Staff staff = new Staff();
|
Staff staff = new Staff();
|
||||||
staff.Name = "Arnie Admin";
|
staff.Name = "Arnie Admin";
|
||||||
staff.Roles = new List<string> {"Administrator"};
|
staff.Roles = new List<string> { "Administrator" };
|
||||||
staff.StartDate = new DateTime(2000, 12, 12, 12, 12, 12, DateTimeKind.Utc);
|
staff.StartDate = new DateTime(2000, 12, 12, 12, 12, 12, DateTimeKind.Utc);
|
||||||
|
|
||||||
ITraceWriter traceWriter = new MemoryTraceWriter();
|
ITraceWriter traceWriter = new MemoryTraceWriter();
|
||||||
|
|
||||||
JsonConvert.SerializeObject(
|
JsonConvert.SerializeObject(
|
||||||
staff,
|
staff,
|
||||||
new JsonSerializerSettings {TraceWriter = traceWriter, Converters = {new JavaScriptDateTimeConverter()}});
|
new JsonSerializerSettings { TraceWriter = traceWriter, Converters = { new JavaScriptDateTimeConverter() } });
|
||||||
|
|
||||||
Console.WriteLine(traceWriter);
|
Console.WriteLine(traceWriter);
|
||||||
// 2012-11-11T12:08:42.761 Info Started serializing Newtonsoft.Json.Tests.Serialization.Staff. Path ''.
|
// 2012-11-11T12:08:42.761 Info Started serializing Newtonsoft.Json.Tests.Serialization.Staff. Path ''.
|
||||||
@@ -193,15 +194,15 @@ Newtonsoft.Json Error: 0 : Error!
|
|||||||
JsonConvert.SerializeObject(
|
JsonConvert.SerializeObject(
|
||||||
new TraceTestObject
|
new TraceTestObject
|
||||||
{
|
{
|
||||||
StringArray = new[] {"1", "2"},
|
StringArray = new[] { "1", "2" },
|
||||||
IntList = new List<int> {1, 2},
|
IntList = new List<int> { 1, 2 },
|
||||||
Version = new Version(1, 2, 3, 4),
|
Version = new Version(1, 2, 3, 4),
|
||||||
StringDictionary =
|
StringDictionary =
|
||||||
new Dictionary<string, string>
|
new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{"1", "!"},
|
{ "1", "!" },
|
||||||
{"Two", "!!"},
|
{ "Two", "!!" },
|
||||||
{"III", "!!!"}
|
{ "III", "!!!" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new JsonSerializerSettings
|
new JsonSerializerSettings
|
||||||
@@ -414,7 +415,7 @@ Newtonsoft.Json Error: 0 : Error!
|
|||||||
|
|
||||||
IList<object> l = new List<object>
|
IList<object> l = new List<object>
|
||||||
{
|
{
|
||||||
new Dictionary<string, string> { {"key!", "value!"}},
|
new Dictionary<string, string> { { "key!", "value!" } },
|
||||||
new Version(1, 2, 3, 4)
|
new Version(1, 2, 3, 4)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -475,7 +476,7 @@ Newtonsoft.Json Error: 0 : Error!
|
|||||||
json,
|
json,
|
||||||
new JsonSerializerSettings
|
new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
Converters = {new JavaScriptDateTimeConverter()},
|
Converters = { new JavaScriptDateTimeConverter() },
|
||||||
TraceWriter = traceWriter
|
TraceWriter = traceWriter
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -620,7 +621,7 @@ Newtonsoft.Json Error: 0 : Error!
|
|||||||
LevelFilter = TraceLevel.Verbose
|
LevelFilter = TraceLevel.Verbose
|
||||||
};
|
};
|
||||||
|
|
||||||
JsonConvert.SerializeObject(c, new JsonSerializerSettings {TraceWriter = traceWriter});
|
JsonConvert.SerializeObject(c, new JsonSerializerSettings { TraceWriter = traceWriter });
|
||||||
|
|
||||||
Assert.AreEqual("ShouldSerialize result for property 'Name' on Newtonsoft.Json.Tests.Serialization.ShouldSerializeTestClass: True. Path ''.", traceWriter.TraceRecords[1].Message);
|
Assert.AreEqual("ShouldSerialize result for property 'Name' on Newtonsoft.Json.Tests.Serialization.ShouldSerializeTestClass: True. Path ''.", traceWriter.TraceRecords[1].Message);
|
||||||
Assert.AreEqual(TraceLevel.Verbose, traceWriter.TraceRecords[1].Level);
|
Assert.AreEqual(TraceLevel.Verbose, traceWriter.TraceRecords[1].Level);
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
};
|
};
|
||||||
wrapper.Dictionary = new Dictionary<string, EmployeeReference>
|
wrapper.Dictionary = new Dictionary<string, EmployeeReference>
|
||||||
{
|
{
|
||||||
{"First", new EmployeeReference()}
|
{ "First", new EmployeeReference() }
|
||||||
};
|
};
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(wrapper, Formatting.Indented, new JsonSerializerSettings
|
string json = JsonConvert.SerializeObject(wrapper, Formatting.Indented, new JsonSerializerSettings
|
||||||
@@ -158,8 +158,8 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
}", json);
|
}", json);
|
||||||
|
|
||||||
Wrapper w2 = JsonConvert.DeserializeObject<Wrapper>(json);
|
Wrapper w2 = JsonConvert.DeserializeObject<Wrapper>(json);
|
||||||
CustomAssert.IsInstanceOfType(typeof (List<EmployeeReference>), w2.Array);
|
CustomAssert.IsInstanceOfType(typeof(List<EmployeeReference>), w2.Array);
|
||||||
CustomAssert.IsInstanceOfType(typeof (Dictionary<string, EmployeeReference>), w2.Dictionary);
|
CustomAssert.IsInstanceOfType(typeof(Dictionary<string, EmployeeReference>), w2.Dictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -199,15 +199,15 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
TypeNameHandling = TypeNameHandling.Objects
|
TypeNameHandling = TypeNameHandling.Objects
|
||||||
});
|
});
|
||||||
|
|
||||||
CustomAssert.IsInstanceOfType(typeof (EmployeeReference), employee);
|
CustomAssert.IsInstanceOfType(typeof(EmployeeReference), employee);
|
||||||
Assert.AreEqual("Name!", ((EmployeeReference) employee).Name);
|
Assert.AreEqual("Name!", ((EmployeeReference)employee).Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
|
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
|
||||||
[Test]
|
[Test]
|
||||||
public void DeserializeTypeNameFromGacAssembly()
|
public void DeserializeTypeNameFromGacAssembly()
|
||||||
{
|
{
|
||||||
string cookieRef = ReflectionUtils.GetTypeName(typeof (Cookie), FormatterAssemblyStyle.Simple, null);
|
string cookieRef = ReflectionUtils.GetTypeName(typeof(Cookie), FormatterAssemblyStyle.Simple, null);
|
||||||
|
|
||||||
string json = @"{
|
string json = @"{
|
||||||
""$id"": ""1"",
|
""$id"": ""1"",
|
||||||
@@ -219,22 +219,22 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
TypeNameHandling = TypeNameHandling.Objects
|
TypeNameHandling = TypeNameHandling.Objects
|
||||||
});
|
});
|
||||||
|
|
||||||
CustomAssert.IsInstanceOfType(typeof (Cookie), cookie);
|
CustomAssert.IsInstanceOfType(typeof(Cookie), cookie);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void SerializeGenericObjectListWithTypeName()
|
public void SerializeGenericObjectListWithTypeName()
|
||||||
{
|
{
|
||||||
string employeeRef = typeof (EmployeeReference).AssemblyQualifiedName;
|
string employeeRef = typeof(EmployeeReference).AssemblyQualifiedName;
|
||||||
string personRef = typeof (Person).AssemblyQualifiedName;
|
string personRef = typeof(Person).AssemblyQualifiedName;
|
||||||
|
|
||||||
List<object> values = new List<object>
|
List<object> values = new List<object>
|
||||||
{
|
{
|
||||||
new EmployeeReference
|
new EmployeeReference
|
||||||
{
|
{
|
||||||
Name = "Bob",
|
Name = "Bob",
|
||||||
Manager = new EmployeeReference {Name = "Frank"}
|
Manager = new EmployeeReference { Name = "Frank" }
|
||||||
},
|
},
|
||||||
new Person
|
new Person
|
||||||
{
|
{
|
||||||
@@ -278,8 +278,8 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
[Test]
|
[Test]
|
||||||
public void DeserializeGenericObjectListWithTypeName()
|
public void DeserializeGenericObjectListWithTypeName()
|
||||||
{
|
{
|
||||||
string employeeRef = typeof (EmployeeReference).AssemblyQualifiedName;
|
string employeeRef = typeof(EmployeeReference).AssemblyQualifiedName;
|
||||||
string personRef = typeof (Person).AssemblyQualifiedName;
|
string personRef = typeof(Person).AssemblyQualifiedName;
|
||||||
|
|
||||||
string json = @"[
|
string json = @"[
|
||||||
{
|
{
|
||||||
@@ -303,7 +303,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
-2147483648
|
-2147483648
|
||||||
]";
|
]";
|
||||||
|
|
||||||
List<object> values = (List<object>) JsonConvert.DeserializeObject(json, typeof (List<object>), new JsonSerializerSettings
|
List<object> values = (List<object>)JsonConvert.DeserializeObject(json, typeof(List<object>), new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
TypeNameHandling = TypeNameHandling.Objects,
|
TypeNameHandling = TypeNameHandling.Objects,
|
||||||
TypeNameAssemblyFormat = FormatterAssemblyStyle.Full
|
TypeNameAssemblyFormat = FormatterAssemblyStyle.Full
|
||||||
@@ -311,8 +311,8 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
Assert.AreEqual(4, values.Count);
|
Assert.AreEqual(4, values.Count);
|
||||||
|
|
||||||
EmployeeReference e = (EmployeeReference) values[0];
|
EmployeeReference e = (EmployeeReference)values[0];
|
||||||
Person p = (Person) values[1];
|
Person p = (Person)values[1];
|
||||||
|
|
||||||
Assert.AreEqual("Bob", e.Name);
|
Assert.AreEqual("Bob", e.Name);
|
||||||
Assert.AreEqual("Frank", e.Manager.Name);
|
Assert.AreEqual("Frank", e.Manager.Name);
|
||||||
@@ -322,14 +322,14 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
Assert.AreEqual(new DateTime(2000, 12, 30, 0, 0, 0, DateTimeKind.Utc), p.LastModified);
|
Assert.AreEqual(new DateTime(2000, 12, 30, 0, 0, 0, DateTimeKind.Utc), p.LastModified);
|
||||||
|
|
||||||
Assert.AreEqual("String!", values[2]);
|
Assert.AreEqual("String!", values[2]);
|
||||||
Assert.AreEqual((long) int.MinValue, values[3]);
|
Assert.AreEqual((long)int.MinValue, values[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void DeserializeWithBadTypeName()
|
public void DeserializeWithBadTypeName()
|
||||||
{
|
{
|
||||||
string employeeRef = typeof (EmployeeReference).AssemblyQualifiedName;
|
string employeeRef = typeof(EmployeeReference).AssemblyQualifiedName;
|
||||||
string personRef = typeof (Person).AssemblyQualifiedName;
|
string personRef = typeof(Person).AssemblyQualifiedName;
|
||||||
|
|
||||||
string json = @"{
|
string json = @"{
|
||||||
""$id"": ""1"",
|
""$id"": ""1"",
|
||||||
@@ -340,7 +340,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
JsonConvert.DeserializeObject(json, typeof (Person), new JsonSerializerSettings
|
JsonConvert.DeserializeObject(json, typeof(Person), new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
TypeNameHandling = TypeNameHandling.Objects,
|
TypeNameHandling = TypeNameHandling.Objects,
|
||||||
TypeNameAssemblyFormat = FormatterAssemblyStyle.Full
|
TypeNameAssemblyFormat = FormatterAssemblyStyle.Full
|
||||||
@@ -355,7 +355,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
[Test]
|
[Test]
|
||||||
public void DeserializeTypeNameWithNoTypeNameHandling()
|
public void DeserializeTypeNameWithNoTypeNameHandling()
|
||||||
{
|
{
|
||||||
string employeeRef = typeof (EmployeeReference).AssemblyQualifiedName;
|
string employeeRef = typeof(EmployeeReference).AssemblyQualifiedName;
|
||||||
|
|
||||||
string json = @"{
|
string json = @"{
|
||||||
""$id"": ""1"",
|
""$id"": ""1"",
|
||||||
@@ -364,7 +364,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
""Manager"": null
|
""Manager"": null
|
||||||
}";
|
}";
|
||||||
|
|
||||||
JObject o = (JObject) JsonConvert.DeserializeObject(json);
|
JObject o = (JObject)JsonConvert.DeserializeObject(json);
|
||||||
|
|
||||||
Assert.AreEqual(@"{
|
Assert.AreEqual(@"{
|
||||||
""Name"": ""Name!"",
|
""Name"": ""Name!"",
|
||||||
@@ -420,7 +420,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
[Test]
|
[Test]
|
||||||
public void DeserializeGenericTypeName()
|
public void DeserializeGenericTypeName()
|
||||||
{
|
{
|
||||||
string typeName = typeof (SendHttpRequest).AssemblyQualifiedName;
|
string typeName = typeof(SendHttpRequest).AssemblyQualifiedName;
|
||||||
|
|
||||||
string json = @"{
|
string json = @"{
|
||||||
""$type"": """ + typeName + @""",
|
""$type"": """ + typeName + @""",
|
||||||
@@ -441,9 +441,9 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
TypeNameAssemblyFormat = FormatterAssemblyStyle.Full
|
TypeNameAssemblyFormat = FormatterAssemblyStyle.Full
|
||||||
});
|
});
|
||||||
|
|
||||||
CustomAssert.IsInstanceOfType(typeof (SendHttpRequest), message);
|
CustomAssert.IsInstanceOfType(typeof(SendHttpRequest), message);
|
||||||
|
|
||||||
SendHttpRequest request = (SendHttpRequest) message;
|
SendHttpRequest request = (SendHttpRequest)message;
|
||||||
Assert.AreEqual("xyz", request.CorrelationId);
|
Assert.AreEqual("xyz", request.CorrelationId);
|
||||||
Assert.AreEqual(2, request.RequestData.Count);
|
Assert.AreEqual(2, request.RequestData.Count);
|
||||||
Assert.AreEqual("siedemnaście", request.RequestData["Id"]);
|
Assert.AreEqual("siedemnaście", request.RequestData["Id"]);
|
||||||
@@ -452,8 +452,8 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
[Test]
|
[Test]
|
||||||
public void SerializeObjectWithMultipleGenericLists()
|
public void SerializeObjectWithMultipleGenericLists()
|
||||||
{
|
{
|
||||||
string containerTypeName = typeof (Container).AssemblyQualifiedName;
|
string containerTypeName = typeof(Container).AssemblyQualifiedName;
|
||||||
string productListTypeName = typeof (List<Product>).AssemblyQualifiedName;
|
string productListTypeName = typeof(List<Product>).AssemblyQualifiedName;
|
||||||
|
|
||||||
Container container = new Container
|
Container container = new Container
|
||||||
{
|
{
|
||||||
@@ -493,7 +493,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
[Test]
|
[Test]
|
||||||
public void WriteObjectTypeNameForProperty()
|
public void WriteObjectTypeNameForProperty()
|
||||||
{
|
{
|
||||||
string typeNamePropertyRef = ReflectionUtils.GetTypeName(typeof (TypeNameProperty), FormatterAssemblyStyle.Simple, null);
|
string typeNamePropertyRef = ReflectionUtils.GetTypeName(typeof(TypeNameProperty), FormatterAssemblyStyle.Simple, null);
|
||||||
|
|
||||||
TypeNameProperty typeNameProperty = new TypeNameProperty
|
TypeNameProperty typeNameProperty = new TypeNameProperty
|
||||||
{
|
{
|
||||||
@@ -517,9 +517,9 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
TypeNameProperty deserialized = JsonConvert.DeserializeObject<TypeNameProperty>(json);
|
TypeNameProperty deserialized = JsonConvert.DeserializeObject<TypeNameProperty>(json);
|
||||||
Assert.AreEqual("Name!", deserialized.Name);
|
Assert.AreEqual("Name!", deserialized.Name);
|
||||||
CustomAssert.IsInstanceOfType(typeof (TypeNameProperty), deserialized.Value);
|
CustomAssert.IsInstanceOfType(typeof(TypeNameProperty), deserialized.Value);
|
||||||
|
|
||||||
TypeNameProperty nested = (TypeNameProperty) deserialized.Value;
|
TypeNameProperty nested = (TypeNameProperty)deserialized.Value;
|
||||||
Assert.AreEqual("Nested!", nested.Name);
|
Assert.AreEqual("Nested!", nested.Name);
|
||||||
Assert.AreEqual(null, nested.Value);
|
Assert.AreEqual(null, nested.Value);
|
||||||
}
|
}
|
||||||
@@ -527,12 +527,12 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
[Test]
|
[Test]
|
||||||
public void WriteListTypeNameForProperty()
|
public void WriteListTypeNameForProperty()
|
||||||
{
|
{
|
||||||
string listRef = ReflectionUtils.GetTypeName(typeof (List<int>), FormatterAssemblyStyle.Simple, null);
|
string listRef = ReflectionUtils.GetTypeName(typeof(List<int>), FormatterAssemblyStyle.Simple, null);
|
||||||
|
|
||||||
TypeNameProperty typeNameProperty = new TypeNameProperty
|
TypeNameProperty typeNameProperty = new TypeNameProperty
|
||||||
{
|
{
|
||||||
Name = "Name!",
|
Name = "Name!",
|
||||||
Value = new List<int> {1, 2, 3, 4, 5}
|
Value = new List<int> { 1, 2, 3, 4, 5 }
|
||||||
};
|
};
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(typeNameProperty, Formatting.Indented);
|
string json = JsonConvert.SerializeObject(typeNameProperty, Formatting.Indented);
|
||||||
@@ -553,9 +553,9 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
TypeNameProperty deserialized = JsonConvert.DeserializeObject<TypeNameProperty>(json);
|
TypeNameProperty deserialized = JsonConvert.DeserializeObject<TypeNameProperty>(json);
|
||||||
Assert.AreEqual("Name!", deserialized.Name);
|
Assert.AreEqual("Name!", deserialized.Name);
|
||||||
CustomAssert.IsInstanceOfType(typeof (List<int>), deserialized.Value);
|
CustomAssert.IsInstanceOfType(typeof(List<int>), deserialized.Value);
|
||||||
|
|
||||||
List<int> nested = (List<int>) deserialized.Value;
|
List<int> nested = (List<int>)deserialized.Value;
|
||||||
Assert.AreEqual(5, nested.Count);
|
Assert.AreEqual(5, nested.Count);
|
||||||
Assert.AreEqual(1, nested[0]);
|
Assert.AreEqual(1, nested[0]);
|
||||||
Assert.AreEqual(2, nested[1]);
|
Assert.AreEqual(2, nested[1]);
|
||||||
@@ -579,9 +579,9 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
Binder = new CustomSerializationBinder()
|
Binder = new CustomSerializationBinder()
|
||||||
});
|
});
|
||||||
|
|
||||||
CustomAssert.IsInstanceOfType(typeof (Person), p);
|
CustomAssert.IsInstanceOfType(typeof(Person), p);
|
||||||
|
|
||||||
Person person = (Person) p;
|
Person person = (Person)p;
|
||||||
|
|
||||||
Assert.AreEqual("Name!", person.Name);
|
Assert.AreEqual("Name!", person.Name);
|
||||||
}
|
}
|
||||||
@@ -590,7 +590,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
{
|
{
|
||||||
public override Type BindToType(string assemblyName, string typeName)
|
public override Type BindToType(string assemblyName, string typeName)
|
||||||
{
|
{
|
||||||
return typeof (Person);
|
return typeof(Person);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -653,12 +653,12 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
Binder = new TypeNameSerializationBinder("Newtonsoft.Json.Tests.Serialization.{0}, Newtonsoft.Json.Tests")
|
Binder = new TypeNameSerializationBinder("Newtonsoft.Json.Tests.Serialization.{0}, Newtonsoft.Json.Tests")
|
||||||
});
|
});
|
||||||
|
|
||||||
CustomAssert.IsInstanceOfType(typeof (Customer), newValues[0]);
|
CustomAssert.IsInstanceOfType(typeof(Customer), newValues[0]);
|
||||||
Customer customer = (Customer) newValues[0];
|
Customer customer = (Customer)newValues[0];
|
||||||
Assert.AreEqual("Caroline Customer", customer.Name);
|
Assert.AreEqual("Caroline Customer", customer.Name);
|
||||||
|
|
||||||
CustomAssert.IsInstanceOfType(typeof (Purchase), newValues[1]);
|
CustomAssert.IsInstanceOfType(typeof(Purchase), newValues[1]);
|
||||||
Purchase purchase = (Purchase) newValues[1];
|
Purchase purchase = (Purchase)newValues[1];
|
||||||
Assert.AreEqual("Elbow Grease", purchase.ProductName);
|
Assert.AreEqual("Elbow Grease", purchase.ProductName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -709,9 +709,9 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
string json = sw.ToString();
|
string json = sw.ToString();
|
||||||
|
|
||||||
string contentSubClassRef = ReflectionUtils.GetTypeName(typeof (ContentSubClass), FormatterAssemblyStyle.Simple, null);
|
string contentSubClassRef = ReflectionUtils.GetTypeName(typeof(ContentSubClass), FormatterAssemblyStyle.Simple, null);
|
||||||
string dictionaryRef = ReflectionUtils.GetTypeName(typeof (Dictionary<int, IList<ContentBaseClass>>), FormatterAssemblyStyle.Simple, null);
|
string dictionaryRef = ReflectionUtils.GetTypeName(typeof(Dictionary<int, IList<ContentBaseClass>>), FormatterAssemblyStyle.Simple, null);
|
||||||
string listRef = ReflectionUtils.GetTypeName(typeof (List<ContentBaseClass>), FormatterAssemblyStyle.Simple, null);
|
string listRef = ReflectionUtils.GetTypeName(typeof(List<ContentBaseClass>), FormatterAssemblyStyle.Simple, null);
|
||||||
|
|
||||||
string expected = @"{
|
string expected = @"{
|
||||||
""TestMember"": {
|
""TestMember"": {
|
||||||
@@ -749,15 +749,15 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
}
|
}
|
||||||
|
|
||||||
Assert.IsNotNull(anotherTestObject);
|
Assert.IsNotNull(anotherTestObject);
|
||||||
CustomAssert.IsInstanceOfType(typeof (ContentSubClass), anotherTestObject.TestMember);
|
CustomAssert.IsInstanceOfType(typeof(ContentSubClass), anotherTestObject.TestMember);
|
||||||
CustomAssert.IsInstanceOfType(typeof (Dictionary<int, IList<ContentBaseClass>>), anotherTestObject.AnotherTestMember);
|
CustomAssert.IsInstanceOfType(typeof(Dictionary<int, IList<ContentBaseClass>>), anotherTestObject.AnotherTestMember);
|
||||||
Assert.AreEqual(1, anotherTestObject.AnotherTestMember.Count);
|
Assert.AreEqual(1, anotherTestObject.AnotherTestMember.Count);
|
||||||
|
|
||||||
IList<ContentBaseClass> list = anotherTestObject.AnotherTestMember[1];
|
IList<ContentBaseClass> list = anotherTestObject.AnotherTestMember[1];
|
||||||
|
|
||||||
CustomAssert.IsInstanceOfType(typeof (List<ContentBaseClass>), list);
|
CustomAssert.IsInstanceOfType(typeof(List<ContentBaseClass>), list);
|
||||||
Assert.AreEqual(1, list.Count);
|
Assert.AreEqual(1, list.Count);
|
||||||
CustomAssert.IsInstanceOfType(typeof (ContentSubClass), list[0]);
|
CustomAssert.IsInstanceOfType(typeof(ContentSubClass), list[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -783,7 +783,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
Message deserialized = JsonConvert.DeserializeObject<Message>(json);
|
Message deserialized = JsonConvert.DeserializeObject<Message>(json);
|
||||||
|
|
||||||
SearchDetails searchDetails = (SearchDetails) deserialized.Body;
|
SearchDetails searchDetails = (SearchDetails)deserialized.Body;
|
||||||
// Json.NET
|
// Json.NET
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -799,13 +799,13 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
{
|
{
|
||||||
Dictionary<string, object> collection = new Dictionary<string, object>()
|
Dictionary<string, object> collection = new Dictionary<string, object>()
|
||||||
{
|
{
|
||||||
{"First", new UrlStatus {Status = 404, Url = @"http://www.bing.com"}},
|
{ "First", new UrlStatus { Status = 404, Url = @"http://www.bing.com" } },
|
||||||
{"Second", new UrlStatus {Status = 400, Url = @"http://www.google.com"}},
|
{ "Second", new UrlStatus { Status = 400, Url = @"http://www.google.com" } },
|
||||||
{
|
{
|
||||||
"List", new List<UrlStatus>
|
"List", new List<UrlStatus>
|
||||||
{
|
{
|
||||||
new UrlStatus {Status = 300, Url = @"http://www.yahoo.com"},
|
new UrlStatus { Status = 300, Url = @"http://www.yahoo.com" },
|
||||||
new UrlStatus {Status = 200, Url = @"http://www.askjeeves.com"}
|
new UrlStatus { Status = 200, Url = @"http://www.askjeeves.com" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -816,7 +816,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
|
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
|
||||||
});
|
});
|
||||||
|
|
||||||
string urlStatusTypeName = ReflectionUtils.GetTypeName(typeof (UrlStatus), FormatterAssemblyStyle.Simple, null);
|
string urlStatusTypeName = ReflectionUtils.GetTypeName(typeof(UrlStatus), FormatterAssemblyStyle.Simple, null);
|
||||||
|
|
||||||
Assert.AreEqual(@"{
|
Assert.AreEqual(@"{
|
||||||
""$type"": ""System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib"",
|
""$type"": ""System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib"",
|
||||||
@@ -853,13 +853,13 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
|
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
|
||||||
});
|
});
|
||||||
|
|
||||||
CustomAssert.IsInstanceOfType(typeof (Dictionary<string, object>), c);
|
CustomAssert.IsInstanceOfType(typeof(Dictionary<string, object>), c);
|
||||||
|
|
||||||
Dictionary<string, object> newCollection = (Dictionary<string, object>) c;
|
Dictionary<string, object> newCollection = (Dictionary<string, object>)c;
|
||||||
Assert.AreEqual(3, newCollection.Count);
|
Assert.AreEqual(3, newCollection.Count);
|
||||||
Assert.AreEqual(@"http://www.bing.com", ((UrlStatus) newCollection["First"]).Url);
|
Assert.AreEqual(@"http://www.bing.com", ((UrlStatus)newCollection["First"]).Url);
|
||||||
|
|
||||||
List<UrlStatus> statues = (List<UrlStatus>) newCollection["List"];
|
List<UrlStatus> statues = (List<UrlStatus>)newCollection["List"];
|
||||||
Assert.AreEqual(2, statues.Count);
|
Assert.AreEqual(2, statues.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -871,7 +871,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
CustomEnumerable<Product> products = new CustomEnumerable<Product>();
|
CustomEnumerable<Product> products = new CustomEnumerable<Product>();
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(products, Formatting.Indented, new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.All});
|
string json = JsonConvert.SerializeObject(products, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All });
|
||||||
|
|
||||||
Assert.AreEqual(@"{
|
Assert.AreEqual(@"{
|
||||||
""$type"": """ + productClassRef + @""",
|
""$type"": """ + productClassRef + @""",
|
||||||
@@ -942,8 +942,8 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
{
|
{
|
||||||
Car testerObject = new Car();
|
Car testerObject = new Car();
|
||||||
testerObject.Year = new DateTime(2000, 10, 5, 1, 1, 1, DateTimeKind.Utc);
|
testerObject.Year = new DateTime(2000, 10, 5, 1, 1, 1, DateTimeKind.Utc);
|
||||||
byte[] data = new byte[] {75, 65, 82, 73, 82, 65};
|
byte[] data = new byte[] { 75, 65, 82, 73, 82, 65 };
|
||||||
testerObject.Objects = new object[] {data, "prueba"};
|
testerObject.Objects = new object[] { data, "prueba" };
|
||||||
|
|
||||||
JsonSerializerSettings jsonSettings = new JsonSerializerSettings();
|
JsonSerializerSettings jsonSettings = new JsonSerializerSettings();
|
||||||
jsonSettings.NullValueHandling = NullValueHandling.Ignore;
|
jsonSettings.NullValueHandling = NullValueHandling.Ignore;
|
||||||
@@ -951,7 +951,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
string output = JsonConvert.SerializeObject(testerObject, Formatting.Indented, jsonSettings);
|
string output = JsonConvert.SerializeObject(testerObject, Formatting.Indented, jsonSettings);
|
||||||
|
|
||||||
string carClassRef = ReflectionUtils.GetTypeName(typeof (Car), FormatterAssemblyStyle.Simple, null);
|
string carClassRef = ReflectionUtils.GetTypeName(typeof(Car), FormatterAssemblyStyle.Simple, null);
|
||||||
|
|
||||||
Assert.AreEqual(output, @"{
|
Assert.AreEqual(output, @"{
|
||||||
""$type"": """ + carClassRef + @""",
|
""$type"": """ + carClassRef + @""",
|
||||||
@@ -973,7 +973,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
Assert.IsTrue(obj.Objects[0] is byte[]);
|
Assert.IsTrue(obj.Objects[0] is byte[]);
|
||||||
|
|
||||||
byte[] d = (byte[]) obj.Objects[0];
|
byte[] d = (byte[])obj.Objects[0];
|
||||||
CollectionAssert.AreEquivalent(data, d);
|
CollectionAssert.AreEquivalent(data, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -996,9 +996,9 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
//Test Json Serialization
|
//Test Json Serialization
|
||||||
//This fails because the JsonSerializer doesn't serialize type names correctly for ISerializable objects
|
//This fails because the JsonSerializer doesn't serialize type names correctly for ISerializable objects
|
||||||
//Type Names should be serialized for All, Auto and Object modes
|
//Type Names should be serialized for All, Auto and Object modes
|
||||||
this.TestJsonSerializationRoundTrip(w, TypeNameHandling.All);
|
TestJsonSerializationRoundTrip(w, TypeNameHandling.All);
|
||||||
this.TestJsonSerializationRoundTrip(w, TypeNameHandling.Auto);
|
TestJsonSerializationRoundTrip(w, TypeNameHandling.Auto);
|
||||||
this.TestJsonSerializationRoundTrip(w, TypeNameHandling.Objects);
|
TestJsonSerializationRoundTrip(w, TypeNameHandling.Objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TestJsonSerializationRoundTrip(SerializableWrapper e, TypeNameHandling flag)
|
private void TestJsonSerializationRoundTrip(SerializableWrapper e, TypeNameHandling flag)
|
||||||
@@ -1135,17 +1135,17 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
TypeNameList<object> l2 = JsonConvert.DeserializeObject<TypeNameList<object>>(json);
|
TypeNameList<object> l2 = JsonConvert.DeserializeObject<TypeNameList<object>>(json);
|
||||||
Assert.AreEqual(4, l2.Count);
|
Assert.AreEqual(4, l2.Count);
|
||||||
|
|
||||||
CustomAssert.IsInstanceOfType(typeof (TestComponentSimple), l2[0]);
|
CustomAssert.IsInstanceOfType(typeof(TestComponentSimple), l2[0]);
|
||||||
CustomAssert.IsInstanceOfType(typeof (Employee), l2[1]);
|
CustomAssert.IsInstanceOfType(typeof(Employee), l2[1]);
|
||||||
CustomAssert.IsInstanceOfType(typeof (string), l2[2]);
|
CustomAssert.IsInstanceOfType(typeof(string), l2[2]);
|
||||||
CustomAssert.IsInstanceOfType(typeof (long), l2[3]);
|
CustomAssert.IsInstanceOfType(typeof(long), l2[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TypeNameDictionary()
|
public void TypeNameDictionary()
|
||||||
{
|
{
|
||||||
TypeNameDictionary<object> l = new TypeNameDictionary<object>();
|
TypeNameDictionary<object> l = new TypeNameDictionary<object>();
|
||||||
l.Add("First", new TestComponentSimple {MyProperty = 1});
|
l.Add("First", new TestComponentSimple { MyProperty = 1 });
|
||||||
l.Add("Second", "String!");
|
l.Add("Second", "String!");
|
||||||
l.Add("Third", long.MaxValue);
|
l.Add("Third", long.MaxValue);
|
||||||
|
|
||||||
@@ -1162,10 +1162,10 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
TypeNameDictionary<object> l2 = JsonConvert.DeserializeObject<TypeNameDictionary<object>>(json);
|
TypeNameDictionary<object> l2 = JsonConvert.DeserializeObject<TypeNameDictionary<object>>(json);
|
||||||
Assert.AreEqual(3, l2.Count);
|
Assert.AreEqual(3, l2.Count);
|
||||||
|
|
||||||
CustomAssert.IsInstanceOfType(typeof (TestComponentSimple), l2["First"]);
|
CustomAssert.IsInstanceOfType(typeof(TestComponentSimple), l2["First"]);
|
||||||
Assert.AreEqual(1, ((TestComponentSimple) l2["First"]).MyProperty);
|
Assert.AreEqual(1, ((TestComponentSimple)l2["First"]).MyProperty);
|
||||||
CustomAssert.IsInstanceOfType(typeof (string), l2["Second"]);
|
CustomAssert.IsInstanceOfType(typeof(string), l2["Second"]);
|
||||||
CustomAssert.IsInstanceOfType(typeof (long), l2["Third"]);
|
CustomAssert.IsInstanceOfType(typeof(long), l2["Third"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -1173,9 +1173,9 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
{
|
{
|
||||||
TypeNameObject o1 = new TypeNameObject();
|
TypeNameObject o1 = new TypeNameObject();
|
||||||
|
|
||||||
o1.Object1 = new TestComponentSimple {MyProperty = 1};
|
o1.Object1 = new TestComponentSimple { MyProperty = 1 };
|
||||||
o1.Object2 = 123;
|
o1.Object2 = 123;
|
||||||
o1.ObjectNotHandled = new TestComponentSimple {MyProperty = int.MaxValue};
|
o1.ObjectNotHandled = new TestComponentSimple { MyProperty = int.MaxValue };
|
||||||
o1.String = "String!";
|
o1.String = "String!";
|
||||||
o1.Integer = int.MaxValue;
|
o1.Integer = int.MaxValue;
|
||||||
|
|
||||||
@@ -1197,10 +1197,10 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
TypeNameObject o2 = JsonConvert.DeserializeObject<TypeNameObject>(json);
|
TypeNameObject o2 = JsonConvert.DeserializeObject<TypeNameObject>(json);
|
||||||
Assert.IsNotNull(o2);
|
Assert.IsNotNull(o2);
|
||||||
|
|
||||||
CustomAssert.IsInstanceOfType(typeof (TestComponentSimple), o2.Object1);
|
CustomAssert.IsInstanceOfType(typeof(TestComponentSimple), o2.Object1);
|
||||||
Assert.AreEqual(1, ((TestComponentSimple) o2.Object1).MyProperty);
|
Assert.AreEqual(1, ((TestComponentSimple)o2.Object1).MyProperty);
|
||||||
CustomAssert.IsInstanceOfType(typeof (long), o2.Object2);
|
CustomAssert.IsInstanceOfType(typeof(long), o2.Object2);
|
||||||
CustomAssert.IsInstanceOfType(typeof (JObject), o2.ObjectNotHandled);
|
CustomAssert.IsInstanceOfType(typeof(JObject), o2.ObjectNotHandled);
|
||||||
Assert.AreEqual(@"{
|
Assert.AreEqual(@"{
|
||||||
""MyProperty"": 2147483647
|
""MyProperty"": 2147483647
|
||||||
}", o2.ObjectNotHandled.ToString());
|
}", o2.ObjectNotHandled.ToString());
|
||||||
@@ -1214,7 +1214,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
{
|
{
|
||||||
1,
|
1,
|
||||||
"two",
|
"two",
|
||||||
new TestComponentSimple {MyProperty = 1}
|
new TestComponentSimple { MyProperty = 1 }
|
||||||
};
|
};
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(c1, Formatting.Indented);
|
string json = JsonConvert.SerializeObject(c1, Formatting.Indented);
|
||||||
@@ -1232,10 +1232,10 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
PropertyItemTypeNameHandling c2 = JsonConvert.DeserializeObject<PropertyItemTypeNameHandling>(json);
|
PropertyItemTypeNameHandling c2 = JsonConvert.DeserializeObject<PropertyItemTypeNameHandling>(json);
|
||||||
Assert.AreEqual(3, c2.Data.Count);
|
Assert.AreEqual(3, c2.Data.Count);
|
||||||
|
|
||||||
CustomAssert.IsInstanceOfType(typeof (long), c2.Data[0]);
|
CustomAssert.IsInstanceOfType(typeof(long), c2.Data[0]);
|
||||||
CustomAssert.IsInstanceOfType(typeof (string), c2.Data[1]);
|
CustomAssert.IsInstanceOfType(typeof(string), c2.Data[1]);
|
||||||
CustomAssert.IsInstanceOfType(typeof (TestComponentSimple), c2.Data[2]);
|
CustomAssert.IsInstanceOfType(typeof(TestComponentSimple), c2.Data[2]);
|
||||||
TestComponentSimple c = (TestComponentSimple) c2.Data[2];
|
TestComponentSimple c = (TestComponentSimple)c2.Data[2];
|
||||||
Assert.AreEqual(1, c.MyProperty);
|
Assert.AreEqual(1, c.MyProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1246,7 +1246,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
{
|
{
|
||||||
Data = new List<object>
|
Data = new List<object>
|
||||||
{
|
{
|
||||||
new TestComponentSimple {MyProperty = 1},
|
new TestComponentSimple { MyProperty = 1 },
|
||||||
new List<object>
|
new List<object>
|
||||||
{
|
{
|
||||||
new List<object>
|
new List<object>
|
||||||
@@ -1278,10 +1278,10 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
PropertyItemTypeNameHandling c2 = JsonConvert.DeserializeObject<PropertyItemTypeNameHandling>(json);
|
PropertyItemTypeNameHandling c2 = JsonConvert.DeserializeObject<PropertyItemTypeNameHandling>(json);
|
||||||
Assert.AreEqual(2, c2.Data.Count);
|
Assert.AreEqual(2, c2.Data.Count);
|
||||||
|
|
||||||
CustomAssert.IsInstanceOfType(typeof (TestComponentSimple), c2.Data[0]);
|
CustomAssert.IsInstanceOfType(typeof(TestComponentSimple), c2.Data[0]);
|
||||||
CustomAssert.IsInstanceOfType(typeof (List<object>), c2.Data[1]);
|
CustomAssert.IsInstanceOfType(typeof(List<object>), c2.Data[1]);
|
||||||
List<object> c = (List<object>) c2.Data[1];
|
List<object> c = (List<object>)c2.Data[1];
|
||||||
CustomAssert.IsInstanceOfType(typeof (JArray), c[0]);
|
CustomAssert.IsInstanceOfType(typeof(JArray), c[0]);
|
||||||
|
|
||||||
json = @"{
|
json = @"{
|
||||||
""Data"": [
|
""Data"": [
|
||||||
@@ -1304,12 +1304,12 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
c2 = JsonConvert.DeserializeObject<PropertyItemTypeNameHandling>(json);
|
c2 = JsonConvert.DeserializeObject<PropertyItemTypeNameHandling>(json);
|
||||||
Assert.AreEqual(2, c2.Data.Count);
|
Assert.AreEqual(2, c2.Data.Count);
|
||||||
|
|
||||||
CustomAssert.IsInstanceOfType(typeof (TestComponentSimple), c2.Data[0]);
|
CustomAssert.IsInstanceOfType(typeof(TestComponentSimple), c2.Data[0]);
|
||||||
CustomAssert.IsInstanceOfType(typeof (List<object>), c2.Data[1]);
|
CustomAssert.IsInstanceOfType(typeof(List<object>), c2.Data[1]);
|
||||||
c = (List<object>) c2.Data[1];
|
c = (List<object>)c2.Data[1];
|
||||||
CustomAssert.IsInstanceOfType(typeof (JObject), c[0]);
|
CustomAssert.IsInstanceOfType(typeof(JObject), c[0]);
|
||||||
JObject o = (JObject) c[0];
|
JObject o = (JObject)c[0];
|
||||||
Assert.AreEqual(1, (int) o["MyProperty"]);
|
Assert.AreEqual(1, (int)o["MyProperty"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -1320,7 +1320,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
Data = new Dictionary<string, object>
|
Data = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
"one", new TestComponentSimple {MyProperty = 1}
|
"one", new TestComponentSimple { MyProperty = 1 }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"two", new Dictionary<string, object>
|
"two", new Dictionary<string, object>
|
||||||
@@ -1328,7 +1328,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
{
|
{
|
||||||
"one", new Dictionary<string, object>
|
"one", new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{"one", 1}
|
{ "one", 1 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1355,10 +1355,10 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
PropertyItemTypeNameHandlingDictionary c2 = JsonConvert.DeserializeObject<PropertyItemTypeNameHandlingDictionary>(json);
|
PropertyItemTypeNameHandlingDictionary c2 = JsonConvert.DeserializeObject<PropertyItemTypeNameHandlingDictionary>(json);
|
||||||
Assert.AreEqual(2, c2.Data.Count);
|
Assert.AreEqual(2, c2.Data.Count);
|
||||||
|
|
||||||
CustomAssert.IsInstanceOfType(typeof (TestComponentSimple), c2.Data["one"]);
|
CustomAssert.IsInstanceOfType(typeof(TestComponentSimple), c2.Data["one"]);
|
||||||
CustomAssert.IsInstanceOfType(typeof(Dictionary<string, object>), c2.Data["two"]);
|
CustomAssert.IsInstanceOfType(typeof(Dictionary<string, object>), c2.Data["two"]);
|
||||||
Dictionary<string, object> c = (Dictionary<string, object>)c2.Data["two"];
|
Dictionary<string, object> c = (Dictionary<string, object>)c2.Data["two"];
|
||||||
CustomAssert.IsInstanceOfType(typeof (JObject), c["one"]);
|
CustomAssert.IsInstanceOfType(typeof(JObject), c["one"]);
|
||||||
|
|
||||||
json = @"{
|
json = @"{
|
||||||
""Data"": {
|
""Data"": {
|
||||||
@@ -1384,8 +1384,8 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
c = (Dictionary<string, object>)c2.Data["two"];
|
c = (Dictionary<string, object>)c2.Data["two"];
|
||||||
CustomAssert.IsInstanceOfType(typeof(JObject), c["one"]);
|
CustomAssert.IsInstanceOfType(typeof(JObject), c["one"]);
|
||||||
|
|
||||||
JObject o = (JObject) c["one"];
|
JObject o = (JObject)c["one"];
|
||||||
Assert.AreEqual(1, (int) o["MyProperty"]);
|
Assert.AreEqual(1, (int)o["MyProperty"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -1750,10 +1750,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
public interface IExample
|
public interface IExample
|
||||||
: ISerializable
|
: ISerializable
|
||||||
{
|
{
|
||||||
String Name
|
String Name { get; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
@@ -1762,17 +1759,17 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
{
|
{
|
||||||
public Example(String name)
|
public Example(String name)
|
||||||
{
|
{
|
||||||
this.Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Example(SerializationInfo info, StreamingContext context)
|
protected Example(SerializationInfo info, StreamingContext context)
|
||||||
{
|
{
|
||||||
this.Name = info.GetString("name");
|
Name = info.GetString("name");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GetObjectData(SerializationInfo info, StreamingContext context)
|
public void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||||
{
|
{
|
||||||
info.AddValue("name", this.Name);
|
info.AddValue("name", Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String Name { get; set; }
|
public String Name { get; set; }
|
||||||
@@ -1783,7 +1780,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
if (ReferenceEquals(this, obj)) return true;
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
if (obj is IExample)
|
if (obj is IExample)
|
||||||
{
|
{
|
||||||
return this.Name.Equals(((IExample)obj).Name);
|
return Name.Equals(((IExample)obj).Name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1850,10 +1847,13 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
{
|
{
|
||||||
public object Object1 { get; set; }
|
public object Object1 { get; set; }
|
||||||
public object Object2 { get; set; }
|
public object Object2 { get; set; }
|
||||||
|
|
||||||
[JsonProperty(TypeNameHandling = TypeNameHandling.None)]
|
[JsonProperty(TypeNameHandling = TypeNameHandling.None)]
|
||||||
public object ObjectNotHandled { get; set; }
|
public object ObjectNotHandled { get; set; }
|
||||||
|
|
||||||
public string String { get; set; }
|
public string String { get; set; }
|
||||||
public int Integer { get; set; }
|
public int Integer { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -123,7 +123,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
{
|
{
|
||||||
public SerializableType(string protectedFieldValue)
|
public SerializableType(string protectedFieldValue)
|
||||||
{
|
{
|
||||||
this.protectedField = protectedFieldValue;
|
protectedField = protectedFieldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string publicField;
|
public string publicField;
|
||||||
@@ -134,14 +134,8 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
public string PublicProperty
|
public string PublicProperty
|
||||||
{
|
{
|
||||||
get
|
get { return privateField; }
|
||||||
{
|
set { privateField = value; }
|
||||||
return privateField;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
this.privateField = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
|
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
|
||||||
@@ -153,11 +147,11 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
public bool Equals(SerializableType other)
|
public bool Equals(SerializableType other)
|
||||||
{
|
{
|
||||||
return this.publicField == other.publicField &&
|
return publicField == other.publicField &&
|
||||||
this.internalField == other.internalField &&
|
internalField == other.internalField &&
|
||||||
this.protectedInternalField == other.protectedInternalField &&
|
protectedInternalField == other.protectedInternalField &&
|
||||||
this.protectedField == other.protectedField &&
|
protectedField == other.protectedField &&
|
||||||
this.privateField == other.privateField;
|
privateField == other.privateField;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,6 +27,7 @@ using System;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ using System.Collections;
|
|||||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||||
#else
|
#else
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Tests
|
namespace Newtonsoft.Json.Tests
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ namespace Newtonsoft.Json.Tests.TestObjects
|
|||||||
{
|
{
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||||
public CircularReferenceClass Child { get; set; }
|
public CircularReferenceClass Child { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user