0

I have a generic model called Message that has a string called route and a payload. What the payload actually is dependant on the route. So for instance if(Route == "Subscribe") then payload is the subscribe model. if(Route == "Post") then payload has the Post model. Is there anyway I can deserialize to a generic Message model like this:

class Message<T> {
    string Route { get; set; }

    T PayLoad { get; set; }
}

And my deserialization function creates Message correctly based on the route?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • http://www.newtonsoft.com/json/help/html/serializetypenamehandling.htm – Ondrej Svejdar Dec 09 '16 at 10:27
  • 1
    See [Deserializing polymorphic json classes without type information using json.net](https://stackoverflow.com/q/19307752/3744182). – dbc Dec 09 '16 at 17:11

0 Answers0