-Increment version to 5.0.5
This commit is contained in:
@@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user