Is there a way to register/use a "global" ContractResolver when using the the ApsNetCore.JsonPatch (2.1.1) package?
I ran into an issue where the path was not resolved because the properties in my Models are in PascalCase but the path in the JsonPatch is in SnakeCase.
In this case I have to set the ContractResolver on the JsonPatchDocument to the Default/Globally registered ContractResolver in the Startup.cs file.
It works but I would have to do this for every Patch Route I am going to implement.
Startup configuration:
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
})
}
Controller:
[HttpPatch("{id}"]
[Consumes(MediaTypeNames.Application.Json)]
public async Task<IActionResult> Patch(string id,
[FromBody] JsonPatchDocument<Entity> patchEntity)
{
...
patchEntity.ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
};
patchEntity.ApplyTo(entity);
...