I am trying to set different JsonSerializerOptions
for specific controllers. Specifically, I want to set ReferenceHandler = ReferenceHandler.Preserve
for those controllers only, and inherit the rest of the serializer options from some static instance.
I'm looking for a way to do this at the controller level, using System.Text.Json
on ASP.NET Core 6.0.
I was able to do this for serialization using an Action Filter using this solution: https://stackoverflow.com/a/56127866/2719183, but I haven't been able to find a good solution to implement this for deserialization. For example, https://stackoverflow.com/a/66256442/2719183, does not work for me because it requires an attribute for each parameter.
How do I override an input formatter at the controller level?