I have an object I am attempting to deserialize with Newtonsoft.Json but it's giving me trouble due to properties containing dashes. The event-data property has a dash for example.
{
"signature": {
"timestamp": "3421342",
"token": "88f79ede5e9af44d6a2",
"signature": "a57233ab698324dbf1ca9dff"
},
"event-data": { ... }
}
I don't have control over the BaseEvent
model I am deserializing to but I did extend it to MyEvent
to add some custom code for other stuff. So I am unable to decorate [JsonProperty]
on properties. So I need to do this using either a contract resolver or some other more global method but ideally localized to just this model (an attribute decorator of some sort).
I was able to add this KebabCaseNamingStrategy
decorator on my model which appears to be exactly what I need but it didn't do anything until I used the new
keyword to hide the base class member. Then EventData
gets deserialized (although the child properties on it containing dashes are not deserialized).
[JsonObject(NamingStrategyType = typeof(KebabCaseNamingStrategy))]
public class MyEvent : BaseEvent
{
public new EventDataObject EventData { get; set; }
}