Reputation: 5043
In general Servicestack works very well on deserializing objects passed as parameters.
For complex objects passed on the querystring it looks for a JSV format as explained here
To deserialize a complex DTO passed in the querystring not in JSV I have registered a custom request binder in my AppHost file in the form
this.RegisterRequestBinder<MyCutommRequestDto>(httpReq => new MyCutommRequestDto()
{
Filters = CustomRequestDtoConverter.GetFilters(httpReq.QueryString)
}
);
In the DTO there are also other properties and I'd like that the rest of their deserialization would be done by Servicestack as normal. Is this possible?
I'd like also to apply this kind of deserialization on all the DTOs that have the same kind of property (different DTOs but all with the Filters property).
Upvotes: 2
Views: 916
Reputation: 143399
Rather than using a RequestBinder (which overrides the default Request Binding with your own) you could instead use a Request Filter and apply generic functionality to all DTO's which implement a shared custom IHasFilter
interface, e.g:
this.RequestFilters.Add((httpReq, httpResp, requestDto) =>
{
var hasFilter = requestDto as IHasFilter;
if (hasFilter != null)
{
hasFilter.Filters = CustomDtoConverter.GetFilters(httpReq.QueryString);
}
});
That way ServiceStack continues to deserialize the Request and you're able to apply your own deserialization logic afterwards.
Upvotes: 1