You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Azure Function App issue: setting JsonSerializerOptions not working with Cosmos input bindings
Issue
Custom JSON Serialization options are ignored when deserializing CosmosDB input bindings. The main issue for my project is this then leads to Enums in third party classes (Ms Graph SDK) causing an exception.
MessageFromBinding.cs (the http triggered function with the CosmosDb input binding)
[Function("MessageFromBinding")]publicIActionResultRun([HttpTrigger(AuthorizationLevel.Function,"post",Route="messageFromBinding/{messageId}")]HttpRequestreq,[CosmosDBInput(databaseName:"%COSMOS_DB_NAME%",containerName:"%COSMOS_DB_CONTAINER_NAME%",Connection="COSMOS_DB_CONNECTION",Id="{messageId}",PartitionKey="{messageId}")]MessagecosmosDbMessage){_logger.LogInformation("cosmosDbMessage received: {@cosmosDbMessage}",cosmosDbMessage);_logger.LogInformation("C# HTTP trigger function processed a request.");returnnewOkObjectResult("Welcome to Azure Functions!");}
The error
Error:System.Text.Json.JsonException: The JSON value could not be converted to System.Nullable`1[FuncJsonIssue.Models.Sentiment].
The text was updated successfully, but these errors were encountered:
Hi @liliankasem. Thank you for looking at this. I have tried the workaround and it does not help.
liliankasem
added
bug
Something isn't working
and removed
potential-bug
Items opened using the bug report template, not yet triaged and confirmed as a bug
labels
Jan 10, 2025
Description
Azure Function App issue: setting JsonSerializerOptions not working with Cosmos input bindings
Issue
Custom JSON Serialization options are ignored when deserializing CosmosDB input bindings. The main issue for my project is this then leads to Enums in third party classes (Ms Graph SDK) causing an exception.
This repo recreates the issue.
This issue us related to the FromBody issue here.
Refs
Documentation followed for Customizing JSON serialization
Related issues: Unable to override the JsonSerializer when using ConfigureFunctionsWebApplication
Note adding the JsonConverter attribute is not an option as the classes are third party (Kiota generated).
Steps to reproduce
Create a dotnet isolated Function App with a fucntion that has CosmosDb input binding...
Program.cs (the config)
Message.cs (a class with an enum property)
MessageFromBinding.cs (the http triggered function with the CosmosDb input binding)
The error
Error:System.Text.Json.JsonException: The JSON value could not be converted to System.Nullable`1[FuncJsonIssue.Models.Sentiment].
The text was updated successfully, but these errors were encountered: