Skip to content

[dotnet/c#] Is it possible to customize the serialization for a Kiota generated .net client? (and how) #5972

Answered by esbenbach
esbenbach asked this question in Q&A
Discussion options

You must be logged in to vote

Since we already create a HttpClientRequestAdapter our solution is currently to do as follows:

        var jsonSerializerOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web);
        jsonSerializerOptions.Converters.Add(new CustomDateTimeOffsetConverter());
        var ctx = new KiotaJsonSerializationContext(jsonSerializerOptions);
        var serializationWriterFactory = new JsonSerializationWriterFactory(ctx);
        
        var adapter = new HttpClientRequestAdapter(authentication, serializationWriterFactory: serializationWriterFactory, httpClient: this.httpClient)
        {
            BaseUrl = $"{account.BaseUrl}"
        };

I have no idea if this is the most appropriat…

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
7 replies
@esbenbach
Comment options

@esbenbach
Comment options

@baywet
Comment options

baywet Jan 10, 2025
Collaborator

@esbenbach
Comment options

@esbenbach
Comment options

Comment options

You must be logged in to vote
1 reply
@baywet
Comment options

baywet Jan 13, 2025
Collaborator

Answer selected by baywet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants