-
Notifications
You must be signed in to change notification settings - Fork 442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Azure Functions do not respect global Json.Net SerializerSettings #5841
Comments
I am also running into this issue, since we want to set additional JsonOptions in our Startup.cs file, but there doesn't seem to be a way to do that. In older functions versions, we could call @mhoeger, is there any way to configure json options in Functions v3 at the moment? |
Same problem here. I need to set As example like: public override void Configure(IFunctionsHostBuilder builder)
{
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
Formatting = Formatting.Indented,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
} |
Any solutions for this very common issue or at least some info if this is possible in future versions? |
This needs to be adressed, it's one of the most basic features. Not only we should be able to set json serialization settings for 'MVC' related stuff, but also we should be able to set DefaultSettings. |
Is there any updates? |
1½ year and no resolution? |
You can create a custom serializer and register it in the startup method
|
Hi @rizksobhi - |
We were able to resolve with the following solution:
|
While @tpaulshippy has a working solution, it really isn't an ideal solution. It would be nice to see an update to this problem. |
What if I want to have different settings for different/each function? |
Bumping this, how can we effectively set the global settings of the included Newtonsoft dependency of Azure functions to avoid "Self referencing loop detected for property", adding [JsonIgnore] to properties is not a durable solution |
I can't help but feel like pulling Newtonsoft in is taking a step backwards rather than a solution... The whole point of |
|
It's been exactly 2 years. I decided to go with the extension method and leave it for now. |
The solution provided on #5841 (comment) it's the best. I can still use |
Bump! It would be nice with a straight forward approach in the Startup.Configure() method as suggested by chatGPT : Adding the attribute to properties that should use it, as done elsewhere, save Azure Functions: Needless to say. This does currently not work. 😥 |
December 2023 and we do not have a solution yet? |
What problem would the feature you're requesting solve? Please describe.
Note that this might be better suited for the Azure Webjobs repository, feel free to let me know/move it
I have some JSON I'd like to be able to convert to an object using custom types, e.g. from NodaTime. I want to be able to put the JSON on a queue, and then have it automatically converted to the correct type.
I can do this in a regular app by configuring the global
JsonConvert.DefaultSettings
method. However when running Azure functions, this is not respected. It seems like Azure Functions uses its own JsonSerializer with its own settings viaMicrosoft.Azure.WebJobs.Host.Protocols.JsonSerialization
,and thus ignores the users own settings.
Let me demonstrate with a code example that does not work
When the second function is hit, this triggers an error
Describe the solution you'd like
There's a few issues here. Of course the solution above with setting
JsonConvert.DefaultSettings
won't work - the settings are set after the object is parsed.I would however expect that when using dependency injection and setting the settings via a Startup class, that the JsonSerializer settings are respected. This is not the case.
Perhaps you could use only your own settings, if the user has not provided them globally?
Describe alternatives you've considered
Use a custom JsonConverter
Json.Net seems to pick up custom JsonConverters when set as attributes. However the catch is that Json.Net automatically converts the date-looking strings into actual Dates, and Nodatime requires the strings to parse them into Nodatime types. See here for more information.
This means that a custom JsonConverter is an alright solution for most cases, but not this one.
Receive it as a string
There is of course the possibility to receive the parameter as a string. However this means you lose out on a lot of other goodness, such as automatic bindings from the value of the class. For perspective, our actual function signature looks something like this
and I'd hate to do all that with dynamic bindings.
The text was updated successfully, but these errors were encountered: