Register
method of the WebApiConfig
class I have set a CamelCasePropertyNamesContractResolver
public static void Register(HttpConfiguration config)
{
//Resto do código removido para brevidade
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
}
This causes the data received (or sent) by JSON to be converted from camelCase
(client-default JavaScript) to TitleCase
(default that I use in properties on the server) and vice versa. p>
Ex. of JSON that the API receives in a PATCH
normal method (without using Delta<T>
)
{
id: 1,
nome: "Joaquim",
idade: 150
}
This is "translated" into
{
Id: 1,
Nome: "Joaquim",
Idade: 150
}
So far so good, the problem is that I have a action
PATCH
on a ApiController
that makes use of
I have read in some places that OData uses a serializer and a deserializer itself and this should be the problem.
Method Delta<T>
of PATCH
:
[HttpPatch, ResponseType(typeof(void))]
public async Task<IHttpActionResult> Patch(int id, [FromBody] Delta<Entity> changes)
{
var entity = await _db.Entities.FindAsync(id);
if (entity == null)
return NotFound();
changes.Patch(entity);
_db.SaveChanges();
return StatusCode(HttpStatusCode.NoContent);
}
Is there any way to treat the " casing " of data received in ApiController
using OData?
Am I going to need to write a new serializer or is there something ready that can help me with this? If you need to write a serializer, can you help me with at least the basic implementation of it?
JSON example I get in method with actions
{ nome: "Teste método PATCH" }
If I send JSON, like the one below, it works fine.
{ Nome: "Teste método PATCH" }
Note: I'm using OWIN, but the application is being hosted on IIS (using the Delta<T>
) package.