-Increment version to 5.0.5

This commit is contained in:
James Newton-King
2013-05-08 20:10:13 +12:00
parent 0f4ad7cd4b
commit f4d5ace26d
4 changed files with 76 additions and 3 deletions
@@ -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()
{
@@ -231,6 +231,18 @@ namespace Newtonsoft.Json.Tests.Serialization
public IDictionary<object, object> ExtensionData;
}
[Test]
public void DeserializeDirectoryAccount()
{
string json = @"{'DisplayName':'John Smith', 'SAMAccountName':'contoso\\johns'}";
DirectoryAccount account = JsonConvert.DeserializeObject<DirectoryAccount>(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<string, JToken> _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];
}
}
}