Nswag: C# Clients custom serialization / deserialization

Created on 21 Mar 2019  路  4Comments  路  Source: RicoSuter/NSwag

Hi,

Are you going to support custom serialization/deserialization for client in the future? (xml, blob, messagePack)

For example, in client constructor:

public SampleClient(string baseUrl, System.Net.Http.HttpClient httpClient, IConverter converter)
{
    BaseUrl = baseUrl;
    _httpClient = httpClient;
    _converter = converter;
    ...
} 

...
if (status_ == "200")
{
        try
        {
            var result_ = await _converter.DeserializeObject<T>(response_).ConfigureAwait(false);
        }
...   
enhancement

Most helpful comment

Was thinking again abaout this and it might make sense to provide this extensibility (and generate a default impl) This might make the templates easier and might be a way to support the new .net core 3.0 JSON serializer...

All 4 comments

Not sure but xml should be supported if the information is in the spec...
blob, i.e. binary should also work when specified (e.g. produces is "application/octet-stream")
messagePack does not make sense as this cannot be expressed by swagger...

My main goal is that the generated output just works and does not need injected services, e.g. external logic...

Was thinking again abaout this and it might make sense to provide this extensibility (and generate a default impl) This might make the templates easier and might be a way to support the new .net core 3.0 JSON serializer...

Thank you for your reply. I'll watch your decision

It might make sense but it's not on my priority list as I probably don't need it soon... maybe this could also solve the problems this PR is trying to solve: https://github.com/RSuter/NSwag/pull/1976

Was this page helpful?
0 / 5 - 0 ratings