I'm using JsonConvert.DefaultSettings in my application to set application-wide default JSON serialization settings (e.g. setting ContractResolver to CamelCasePropertyNamesContractResolver). This causes the client-side validation to fail (specifically in this case due to camel-cased field names ending up in the data- attributes) because ExpressiveAnnotations isn't opting out of using default settings.
Since ExpressiveAnnotations relies on specific JSON formatting for client-side validation, it should follow the recommended approach for libraries by opting out of user-specified default settings. This can be accomplished by creating a JsonSerializer instance instead of using JsonConvert.SerializeObject()as per the Json.NET blog post on the subject:
Because there are cases where JSON should not be customized, e.g. a Facebook or Twitter library, by default JsonSerializer won’t use DefaultSettings, providing an opt-out for those frameworks or for places in your application that shouldn’t use default settings.
This would make it more resilient to unexpected behavior.
I'm using
JsonConvert.DefaultSettings
in my application to set application-wide default JSON serialization settings (e.g. settingContractResolver
toCamelCasePropertyNamesContractResolver
). This causes the client-side validation to fail (specifically in this case due to camel-cased field names ending up in the data- attributes) because ExpressiveAnnotations isn't opting out of using default settings.Since ExpressiveAnnotations relies on specific JSON formatting for client-side validation, it should follow the recommended approach for libraries by opting out of user-specified default settings. This can be accomplished by creating a
JsonSerializer
instance instead of usingJsonConvert.SerializeObject()
as per the Json.NET blog post on the subject:This would make it more resilient to unexpected behavior.