Duplicate of Using a custom type discriminator to tell JSON.net which type of a class hierarchy to deserialize
and JsonConverter how to deserialize to generic object
Thx https://stackoverflow.com/users/3744182/dbc
Consumer application knows Class A, I will serve Class B that inherited from Class A.Class B is defined in server application.
public class A {} // Both Application know it
public class B:A{} // It is defined in Server Application
public A GetAInstanceById(){ // It is written in Server Application, but both application know its method signature, consumer application calls it by simple Web Call
..............
return new B();
}
B response is serialized by JsonConvert.SerializeObject method, with this settings.
settings.TypeNameHandling = TypeNameHandling.All;
When consumer application get the response from server application, it tries to deserialize response to A (because of method signature)
Json.Net could not find B class and convert instance as "object" and throw "object Must Implement IConvertible" exception.
So I want to serialize response as $type:"A" . How can I change $type:"B" to $type:"A"