-CamelCasePropertyNamesContractResolver now updates dictionary and dynamic property names
This commit is contained in:
+44
@@ -167,6 +167,50 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
""Medium"",
|
||||
""Large""
|
||||
]
|
||||
}", json);
|
||||
}
|
||||
|
||||
#if !(NET35 || NET20 || WINDOWS_PHONE)
|
||||
[Test]
|
||||
public void DynamicCamelCasePropertyNames()
|
||||
{
|
||||
dynamic o = new DynamicTests.TestDynamicObject();
|
||||
o.Text = "Text!";
|
||||
o.Integer = int.MaxValue;
|
||||
|
||||
string json = JsonConvert.SerializeObject(o, Formatting.Indented,
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
});
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""text"": ""Text!"",
|
||||
""integer"": 2147483647,
|
||||
""int"": 0,
|
||||
""childObject"": null
|
||||
}", json);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void DictionaryCamelCasePropertyNames()
|
||||
{
|
||||
Dictionary<string, string> values = new Dictionary<string, string>
|
||||
{
|
||||
{"First", "Value1!"},
|
||||
{"Second", "Value2!"}
|
||||
};
|
||||
|
||||
string json = JsonConvert.SerializeObject(values, Formatting.Indented,
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
});
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""first"": ""Value1!"",
|
||||
""second"": ""Value2!""
|
||||
}", json);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Linq.Expressions;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Serialization.Formatters;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Newtonsoft.Json.Tests.TestObjects;
|
||||
using Newtonsoft.Json.Utilities;
|
||||
using NUnit.Framework;
|
||||
|
||||
Reference in New Issue
Block a user