Having json strings like this (I have no control over the publisher):
{
"TypeName": "Type1"
}
{
"TypeName": "Type1"
}
Is this an acceptable way to deserialize the json strings dynamically?:
public class DeserializationFactory
{
public static IPoco GetEvent(string jsonString)
{
var o = JObject.Parse(jsonString);
IPoco poco = null;
switch (o["TypeName"].ToString())
{
case "Type1":
poco = JsonConvert.DeserializeObject<Type1>(jsonString);
break;
case "Type2":
poco = JsonConvert.DeserializeObject<Type2>(jsonString);
break;
}
return poco;
}
}