I am serializing an object of this format using Newtonsoft.JSON:
class Message
{
public HeaderType Header { get; set; }
public object Body { get; set; }
}
I want to turn the Header
and Body
properties into camel case, while presevering the case of the properties of the thing assigned to Body
.
So if the message looks like:
var result = new Message() { Header = myHeader, Body = new SomeClass() { A = 1 }});
I want the output to look like:
{ header = myHeader, body = { A = 1 } } // I realize this isn't valid C#
Right now, I'm doing this to get the camel case conversion, but of course it's affecting everything.
string stringRepresentationOfObj = JsonConvert.SerializeObject(obj, new JsonSerializerSettings {
ContractResolver = new DefaultContractResolver {
NamingStrategy = new CamelCaseNamingStrategy()
}
});
Is there a way to ignore certain parts of the object? I see that the docs call out OverrideSpecifiedNames
, ProcessDictionaryKeys
, and ProcessExtensionDataNames
, but it doesn't look like that's what I want.
Am I forced to use a some kind of custom naming strategy? How can I achieve this?