From f4d5ace26dc768b5a5a4dfbdea7f5c26880151f0 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Wed, 8 May 2013 20:10:13 +1200 Subject: [PATCH] -Increment version to 5.0.5 --- Build/Newtonsoft.Json.nuspec | 2 +- Build/build.ps1 | 4 +- Src/Newtonsoft.Json.Tests/JsonConvertTest.cs | 37 +++++++++++++++++++ .../Serialization/JsonSerializerTest.cs | 36 ++++++++++++++++++ 4 files changed, 76 insertions(+), 3 deletions(-) diff --git a/Build/Newtonsoft.Json.nuspec b/Build/Newtonsoft.Json.nuspec index b0ce63e8..b401cea2 100644 --- a/Build/Newtonsoft.Json.nuspec +++ b/Build/Newtonsoft.Json.nuspec @@ -2,7 +2,7 @@ Newtonsoft.Json - 5.0.4 + 5.0.5 Json.NET Json.NET is a popular high-performance JSON framework for .NET James Newton-King diff --git a/Build/build.ps1 b/Build/build.ps1 index 56839f0c..5909bb14 100644 --- a/Build/build.ps1 +++ b/Build/build.ps1 @@ -1,7 +1,7 @@ properties { - $zipFileName = "Json50r4.zip" + $zipFileName = "Json50r5.zip" $majorVersion = "4.5" - $majorWithReleaseVersion = "5.0.4" + $majorWithReleaseVersion = "5.0.5" $version = GetVersion $majorWithReleaseVersion $signAssemblies = $false $signKeyPath = "D:\Development\Releases\newtonsoft.snk" diff --git a/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs b/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs index afdf77d2..5216365b 100644 --- a/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs @@ -34,6 +34,7 @@ using System.Threading.Tasks; using System.Xml; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Tests.Serialization; using Newtonsoft.Json.Tests.TestObjects; using Newtonsoft.Json.Utilities; @@ -76,6 +77,42 @@ namespace Newtonsoft.Json.Tests } } + [Test] + public void DefaultSettings_Example() + { + JsonConvert.DefaultSettings = () => new JsonSerializerSettings + { + Formatting = Formatting.Indented, + ContractResolver = new CamelCasePropertyNamesContractResolver() + }; + + Employee e = new Employee + { + FirstName = "Eric", + LastName = "Example", + BirthDate = new DateTime(1980, 4, 20, 0, 0, 0, DateTimeKind.Utc), + Department = "IT", + JobTitle = "Web Dude" + }; + + string json = JsonConvert.SerializeObject(e); + // { + // "firstName": "Eric", + // "lastName": "Example", + // "birthDate": "1980-04-20T00:00:00Z", + // "department": "IT", + // "jobTitle": "Web Dude" + // } + + Assert.AreEqual(@"{ + ""firstName"": ""Eric"", + ""lastName"": ""Example"", + ""birthDate"": ""1980-04-20T00:00:00Z"", + ""department"": ""IT"", + ""jobTitle"": ""Web Dude"" +}", json); + } + [Test] public void DefaultSettings_Override() { diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index ed26cdb6..e2cad03f 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -231,6 +231,18 @@ namespace Newtonsoft.Json.Tests.Serialization public IDictionary ExtensionData; } + [Test] + public void DeserializeDirectoryAccount() + { + string json = @"{'DisplayName':'John Smith', 'SAMAccountName':'contoso\\johns'}"; + + DirectoryAccount account = JsonConvert.DeserializeObject(json); + + Assert.AreEqual("John Smith", account.DisplayName); + Assert.AreEqual("contoso", account.Domain); + Assert.AreEqual("johns", account.UserName); + } + [Test] public void SerializePublicExtensionData() { @@ -9314,4 +9326,28 @@ Parameter name: value", get { return FavoriteNumber != 0; } } } + + public class DirectoryAccount + { + // normal deserialization + public string DisplayName { get; set; } + + // these properties are set in OnDeserialized + public string UserName { get; set; } + public string Domain { get; set; } + + [JsonExtensionData] + private IDictionary _additionalData; + + [OnDeserialized] + private void OnDeserialized(StreamingContext context) + { + // SAMAccountName is not deserialized to any property + // and so it is added to the extension data dictionary + string samAccountName = (string)_additionalData["SAMAccountName"]; + + Domain = samAccountName.Split('\\')[0]; + UserName = samAccountName.Split('\\')[1]; + } + } } \ No newline at end of file