microsoft-identity-web icon indicating copy to clipboard operation
microsoft-identity-web copied to clipboard

Allow passing JsonSerializerOptions to DownstreamWebApiGenericExtensions

Open mterwoord opened this issue 2 years ago • 4 comments

Is your feature request related to a problem? Please describe. I'm trying to call a downstream web api usnig IDownstreamWebApi. This works great, except for the fact that I want to use a custom JsonSerializerOptions class, to adjust json bevhavior.

Describe the solution you'd like Add an optional argument to all methods in DownstreamWebApiGenericExtensions, to allow passing in a JsonSerializerOptions instance.

Describe alternatives you've considered What I can do, is basically copy the extensions to my code and do it myself.

Additional context .

mterwoord avatar Sep 26 '21 10:09 mterwoord

To be clear, if this is an enhancement that's ok by the team, I'd be happy to make a PR to implement this. Just want an OK for that first.

mterwoord avatar Sep 26 '21 10:09 mterwoord

@mterwoord Instead of passing-in an option:

  • would it work to inject a serializer in the construction of DownstreamWebApi by dependency injection? (would all the web api use the same serializer ?)
  • otherwise, would it work to have an option in DownstreamWebApiOptions? Maybe an optional delegate to perform the serialization?

could you share for the moment what the public API change you have in mind?

jmprieur avatar Sep 27 '21 00:09 jmprieur

I suggested passing-in a option, because that's how HttpClient.GetFromJsonAsync (extension method) works as well. To me this works nicely.

In my case, my whole api uses the same serializer options. In fact, to me, the HttpClient extensions work great. :-)

mterwoord avatar Sep 27 '21 15:09 mterwoord

Any progress on this? or did i mis something?

MauRiEEZZZ avatar Jun 03 '22 12:06 MauRiEEZZZ

Microsoft.Identity.Web 2.x brings the notion of IDownstreamRestApi which allows you to provide your own serializer. See

https://github.com/AzureAD/microsoft-identity-abstractions-for-dotnet/blob/b2eab97f3c0a3adc2b2bc3f51ba9a4c69c4e1cb8/src/Microsoft.Identity.Abstractions/DownstreamRestApi/DownstreamRestApiOptions.cs#L57-L78

jmprieur avatar Dec 28 '22 05:12 jmprieur