How to deserialize from a JSON-RPC websocket api response to the correct static type

146 views Asked by At

The only way I could figure out what the JSON response could be deserialized to was to look for strings within the JSON to give me a hint on what it could be. This seems very hacky and hoping there is a better way.

Given the 2 example JSON responses, how would I deserialize to the proper static type?

The result field could contain any simple or complex type. In the first example results would be a list of names and the second would be a list of prices.

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": [ "Jane Doe", "Joe Smith" ]
}

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": [ 123, 456 ]
}
0

There are 0 answers