You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've setup a test controller using "Task" and it's interface using refit.
I suspect this isn't ideal and won't work based on what I've read but I wanted a clear answer on subject.
When I use "Task" I get the following error
"System.NotSupportedException: Deserialization of interface types is not supported"
Because the concreate class isn't specified I doubt a custom serializer would help, is that assumption correct?
I've been tasked with evaluating refit for our current project so maybe I'm missing something.
Thanks in advanced :D
The text was updated successfully, but these errors were encountered:
In the case of using the Task<T> return type on a Refit interface, once the HttpResponseMessage has come back Refit simply hands it off to the IHttpContentSerializer implementation you've got configured in order to handle the deserialization, so whatever that supports, it will be able to do. As of Refit 6 System.Text.Json is the default, but it's also possible to use Newtonsoft.Json if you either have some backwards compatibility requirement with existing code/system you're interacting with, or it does something that System.Text.Json doesn't support.
A bit of googling seems to suggest Newtonsoft.Json can certainly handle the task of deserializing to an interface type through use of a custom converter, but when I search the same for System.Text.Json I find a lot of GitHub issues and discussions requesting this feature, which I'm not sure the current status of. RefitSettings allows you to pass any custom settings you need along to the serializer to support your use case.
So, in summary, it is theoretically possible to handle this with Refit today, at least with Newtonsoft.Json, though when/if System.Text.Json supports in the future you could switch to that serializer instead. The same will go for any library trying to provide a nice abstraction over http calls that is delegating the serialization/deserialization concerns to one of those libraries like I imagine all of them do. At least all the code I have read in all libraries like Refit seems to do so. The performance difference between System.Text.Json and Newtonsoft.Json is that, at least in my benchmarks, System.Text.Json takes half the time, and allocates only 2/3 the memory.
I've setup a test controller using "Task" and it's interface using refit.
I suspect this isn't ideal and won't work based on what I've read but I wanted a clear answer on subject.
When I use "Task" I get the following error
"System.NotSupportedException: Deserialization of interface types is not supported"
Because the concreate class isn't specified I doubt a custom serializer would help, is that assumption correct?
I've been tasked with evaluating refit for our current project so maybe I'm missing something.
Thanks in advanced :D
The text was updated successfully, but these errors were encountered: