-Added DefaultContractResolver.ResolveDictionaryKey

-Added JsonDictionaryContract.DictionaryKeyResolver
-Marked JsonDictionaryContract.PropertyNameResolver as obsolete
This commit is contained in:
James Newton-King
2015-05-03 16:56:41 +12:00
parent 841464d014
commit 0929c2b4c3
7 changed files with 71 additions and 8 deletions
@@ -95,6 +95,48 @@ namespace Newtonsoft.Json.Tests.Serialization
[TestFixture]
public class JsonSerializerTest : TestFixtureBase
{
public class DictionaryKeyContractResolver : DefaultContractResolver
{
protected internal override string ResolveDictionaryKey(string dictionaryKey)
{
return dictionaryKey;
}
protected internal override string ResolvePropertyName(string propertyName)
{
return propertyName.ToUpper(CultureInfo.InvariantCulture);
}
}
[Test]
public void DictionaryKeyContractResolverTest()
{
var person = new
{
Name = "James",
Age = 1,
RoleNames = new Dictionary<string, bool>
{
{ "IsAdmin", true },
{ "IsModerator", false }
}
};
string json = JsonConvert.SerializeObject(person, Formatting.Indented, new JsonSerializerSettings
{
ContractResolver = new DictionaryKeyContractResolver()
});
Assert.AreEqual(@"{
""NAME"": ""James"",
""AGE"": 1,
""ROLENAMES"": {
""IsAdmin"": true,
""IsModerator"": false
}
}", json);
}
[Test]
public void IncompleteContainers()
{