ServiceStack のビルトイン デシリアライゼーションを使用してポスト変数をデシリアライズしたいと考えています。しかし、解決しようとしている別の問題に柔軟に対応できるように、2 つの変更を加えたいと思います。
[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; }
}
投稿変数のクラス名が {Property} と一致する場合、その DTO クラスを作成し、それを Dto オブジェクトに格納します。他のすべてを正常にデシリアライズしたい。
たとえば、「example.com/API/MyObject/CommodityType」に次の 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
}
これは、リクエスト フィルタとレスポンス フィルタを使用できる状況ですか? カスタム リクエスト バインダーを作成する必要がありますか? これにアプローチする別の方法はありますか?