I'm working on a protocol in which the receiver will receive json messages of certain specified custom types (currently 5, but could be 10-20). I'm struggling to come up with an optimal/fast solution which will automatically deserialize the json and return the correct type of object.
Example:
public class MessageA
{
public string Message;
}
public class MessageB
{
public int value;
}
public class MessageC
{
public string ValueA;
public string ValueB;
}
Ideally, the method should be like
Object Deserialize(string json);
and it will return one of the three message types OR null - in case there was a parsing error/the json didn't match any of the predefined type.
UPDATE: I have control over sender/receiver as well as the protocol design.