I'm using Json.Net for my website. I want the serializer to serialize property names in camelcase by default. I don't want it to change property names that I manually assign. I have the following code:
public class TestClass
{
public string NormalProperty { get; set; }
[JsonProperty(PropertyName = "CustomName")]
public string ConfiguredProperty { get; set; }
}
public void Experiment()
{
var data = new TestClass { NormalProperty = null,
ConfiguredProperty = null };
var result = JsonConvert.SerializeObject(data,
Formatting.None,
new JsonSerializerSettings {ContractResolver
= new CamelCasePropertyNamesContractResolver()}
);
Console.Write(result);
}
The output from Experiment
is:
{"normalProperty":null,"customName":null}
However, I want the output to be:
{"normalProperty":null,"CustomName":null}
Is this possible to achieve?