I have a class with a 'long' datatype. Using json.net to deserialize the web request containing this object (that is coming in through webapi).
Ex.
public class Employee{
long id,
string name
}
A request like the below deserializes correctly,
{"id":"123","name":"foo"}
(notice the double quotes around value of 'id')
But a request like the below fails to deserialize,
{"id":123,"name":"foo"}
I tried writing a custom JsonConverter and overriding the ReadJson method to convert value to Int64 but it hasn't helped.
Update:
May be I oversimplified my question. Adding more detail.
I encounter this when the type is used as a parameter in an odatacontroller's method
public class mycontroller : odatacontroller
{[HttpPost]
public void Post([FromBody] Employee newEmp)
{
}
}
'null' is received for newEmp when the body is:
{"id":123,"name":"foo"}
I get a valid newEmp object for body like:
{"id":"123","name":"foo"} or
{"name":"foo"} (ie, when id is excluded)