I would like to deserialize a post variable using ServiceStack's built in deserialization. But, I would like to make two changes that will provide me with some flexibility for another problem that I am attempting to solve.
[Route("/MyObject/{Property}", "POST")]
OtherRoutes...
public class MyObject:IReturn<MyObjectResponse>{
public string Property{ get; set; }
public object Dto{ get; set; }
Other properties...
}
public class CommodityType{
public int Id{ get; set; }
public string CommodityTypeName{ get; set; }
}
If the post variable class name matches {Property}, I want to create that DTO class and store that in the Dto object. I want everything else to deserialize normally.
For example if I post to: "example.com/API/MyObject/CommodityType" the following json:
{
"CommodityType":{
"Id": 1,
"CommodityTypeName": "Commercial Services"
}
}
if(MyObject.Property == POST.ObjectName){
// in this example Post.ObjectName = "CommodityType"
// Use Reflection to create object of type MyObject.Property
// Deserialize into the object created by reflection
// MyObject.Dto = Deserialized object
}
Is this a situation where I could use Request and Response filters? Should I create a custom request binder? Is there another way to approach this?