Skip to content

Commit d826592

Browse files
Merge pull request #280381 from mattchenderson/serializer
adding aspnetcore serialization example
2 parents 4c81772 + c139194 commit d826592

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

articles/azure-functions/dotnet-isolated-process-guide.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ This middleware checks for the presence of a specific request header(x-correlati
220220

221221
### Customizing JSON serialization
222222

223-
The isolated worker model uses `System.Text.Json` by default. You can customize the behavior of the serializer by configuring services as part of your `Program.cs` file. The following example shows this using `ConfigureFunctionsWebApplication`, but it will also work for `ConfigureFunctionsWorkerDefaults`:
223+
The isolated worker model uses `System.Text.Json` by default. You can customize the behavior of the serializer by configuring services as part of your `Program.cs` file. This section covers general-purpose serialization and will not influence [HTTP trigger JSON serialization with ASP.NET Core integration](#json-serialization-with-aspnet-core-integration), which must be configured separately.
224+
225+
The following example shows this using `ConfigureFunctionsWebApplication`, but it will also work for `ConfigureFunctionsWorkerDefaults`:
224226

225227
```csharp
226228
var host = new HostBuilder()
@@ -433,6 +435,23 @@ To enable ASP.NET Core integration for HTTP:
433435
}
434436
```
435437

438+
#### JSON serialization with ASP.NET Core integration
439+
440+
ASP.NET Core has its own serialization layer, and it is not affected by [customizing general serialization configuration](#customizing-json-serialization). To customize the serialization behavior used for your HTTP triggers, you need to include an `.AddMvc()` call as part of service registration. The returned `IMvcBuilder` can be used to modify ASP.NET Core's JSON serialization settings. The following example shows how to configure JSON.NET (`Newtonsoft.Json`) for serialization using this approach:
441+
442+
```csharp
443+
var host = new HostBuilder()
444+
.ConfigureFunctionsWebApplication()
445+
.ConfigureServices(services =>
446+
{
447+
services.AddApplicationInsightsTelemetryWorkerService();
448+
services.ConfigureFunctionsApplicationInsights();
449+
services.AddMvc().AddNewtonsoftJson();
450+
})
451+
.Build();
452+
host.Run();
453+
```
454+
436455
### Built-in HTTP model
437456

438457
In the built-in model, the system translates the incoming HTTP request message into an [HttpRequestData] object that is passed to the function. This object provides data from the request, including `Headers`, `Cookies`, `Identities`, `URL`, and optionally a message `Body`. This object is a representation of the HTTP request but isn't directly connected to the underlying HTTP listener or the received message.

0 commit comments

Comments
 (0)