NJsonApiCore icon indicating copy to clipboard operation
NJsonApiCore copied to clipboard

POST/PATCH does not work for many simple types

Open cnolewajka opened this issue 9 years ago • 2 comments

It looks like there is an issue with servicing the POST/PATCH operations.

This is related to how the values are deserialized into the Delta object. It looks like the process does not account for types on the model.

For instance, if you add an int or float, or Decimal, one will notice that the POST/PATCH when trying to do Delta.ToObject() would fail with InvalidCatOperation.

This is due to the fact that the Delta Key/Value pairs have values of types that do not correspond to property types on the model, and the concluded setter requires a proper type. The cast fails when the setter is being invoked.

Is there any way to resolve that at the moment?

cnolewajka avatar Dec 22 '16 13:12 cnolewajka

I found a way to resolve the Decimal case, this should be configured in the JSON deserializer settings: nJsonApiConfig.GetJsonSerializerSettings().FloatParseHandling = Newtonsoft.Json.FloatParseHandling.Decimal;

It looks more like a workaround as it seems it's not possible for instance to mix double and Decimal in the models.

cnolewajka avatar Dec 22 '16 16:12 cnolewajka

Hi @cnolewajka thank you for posting your issue. We have hit the same thing. In our case it treats all integer-like items as long.

brainwipe avatar Jan 19 '17 14:01 brainwipe