0

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 ]
}
user3953989
  • 1,844
  • 3
  • 25
  • 56
  • Pass up some form of `type` property perhaps? – mjwills Apr 06 '20 at 01:46
  • @mjwills It's not my API so I can't change anything server side. Websocket APIs really seem to only be geared toward dynamically typed languages. Even if it did provide a type field, I'd have to search the json and extract that string which seems hokey too. – user3953989 Apr 06 '20 at 12:10

0 Answers0