Open justinyoo opened 3 years ago
I agree. I use .NET6, Azure Functions v3 and OpenAPI v3 and I'm trying to remove the dependency on Newtonsoft.Json
.
I managed to change the deserialization of the body of the HttpTrigger
, but I also use OpenApiExample
and its Build
method depends on Newtonsoft.Json.Serialization.NamingStrategy
@brennfoster It's a historical reason. That's why this issue is for - to give a choice to devs.
This is becoming increasingly important in isolated functions / preparation for the move to .NET 8. Forcing the worker configuration to depend on Newtonsoft is a huge hurdle when wanting to use use System.Text.Json everywhere else (HttpTrigger responses, cosmos serialization, etc.).
This is causing enormous headaches for us when trying to programmatically define Azure API Management operations for HTTP functions. It would be great if we could just generate an OpenAPI spec like we do for our .NET app services, but the JSON library mismatch blocks us from doing that. We have to either graphically import the Function definition from the APIM menu, or write some monstrosity of an az cli script to reproduce what the graphical import does under the hood. There's a good reason why declarative IAC is vastly preferred to procedural IAC and it would be ideal if we could just use Bicep everywhere as intended.
Would someone please help me understand the System.Text.Json support issue. My function works correctly with both serialization and deserialization using System.Text.Json. The SwaggerUI page also loads correctly. I am using NET8 with a function running in isolated/out-of-process mode.
My Program.cs includes this line:
.ConfigureFunctionsWorkerDefaults()
Several iterations ago I was using this setup but no longer use it and don't find any problems:
.ConfigureFunctionsWorkerDefaults(worker =>
{
worker.UseNewtonsoftJson();
})
NewtonsoftJson is only listed as a dependency of Microsoft.Azure.Functions.Worker.Extensions.OpenApi.
I was previously using Azure Functions with NewtonSoftJson but am now only using System.Text.Json.
I do have custom System.Text.Json.JsonSerializerOptions set with my preferred serializer options and custom converters. All seems to be working including DateTimeOffsets and Enums which require custom converters in System.Text.Json.
Long story short, what am I missing by not using worker.UseNewtonsoftJson?
Trying it out, you seem correct in that it is not actually a requirement that the plugin requires the host to .UseNewtonsoftJson()
, which is great news. But really requiring that the supposed requirement is removed from documentation.
Long story short, what am I missing by not using worker.UseNewtonsoftJson?
It seems to me that the effect is that model-samples and openapi-schemas are presented incorrectly, particularly when customized.
For example, STJ's [JsonPropertyOrder(2), JsonPropertyName("SpecialCaseName"))]
are not respected, instead using default NewtonsoftJson serialization, which is unfortunate (particularly JsonPropertyName
, as generated clients etc. will get it wrong), but not a show-stopper like I previously expected.
Any news about that issue? Using System.Text.Json in a function using isolated worker environment is still not working. My function is using .Net 8.0 and Microsoft.Azure.Functions.Worker.Extensions.OpenApi version 1.5.1
Azure Functions v3 has a strong dependency on
Newtonsoft.Json
. For future proof, it should be decoupled from the runtime and support bothSystem.Text.Json
andNewtonsoft.Json
on dev's choice, especially for .NET 5+ isolated worker environment.