Related question: JSON.NET - deserialize JSON into object, which class type is in inner field (but this one is specific to JSON.NET)
Is there a standard or recommended way to deserialise something like:
{
"command" : "register_user",
"params" : {
"@c" : "register_params",
"name" : "sdfsd",
"email" : "sdfsd@ddkdk",
"password" : "JDFffJJJd",
"address" : {
"postcode" : "12345",
"street" : "cherry st",
"number" : "44432",
"country" : "antarctica"
}
}
}
If we told a deserializer to expect a Message
type:
class Message
{
string Command;
object[] params;
}
There doesn't appear to be a JSON deserialization framework (or documentation within one), which can handle such a case.
- Perhaps there is one, or most, framework which simply scans the loaded types within the assembly to find the closest type?
- Perhaps within the JSON standard there is a standard field type for helping a deserializer select the right type?
- Perhaps there is no option but to include such helpers manually (both within the JSON string and in the deserializer logic)?
Thanks
UPDATE
For this particular example here, the implied use is for RPC. In my RPC solution, one needs to bind server objects to the RPC system, and the MethodInfo of each RPC method is cached - therefore the type of each parameter could indeed be fed into the JSON deserializer from the MethodInfo. Nevertheless, this question is still relevant, for example if the graph becomes deeper, with a more complex object then even this would not be enough. Furthermore, I'm sure this problem has/will been/be encountered outside of an RPC case. And all answers may be novel, I will simply pick the solution I believe is best.