From Json.NET to System.Text.Json, Replacing JsonObject(NamingStrategyType) Attribute
13:37 20 Sep 2020

I'm currently replacing Json.NET with System.Text.Json and am stuck at a detail.

The serialized data is used to query a web API. While most of the properties follow CamelCaseNamingPolicy, some of the classes follow SnakeCaseNamingPolicy. I have written a class to apply that policy (ok... copy/pasted from StackOverflow)

The problem is. In System.Text.Json, the NamingPolicy is set directly on the serializer. I haven't seen any equivalent for JsonObjectAttribute.

[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
public class ApiFieldEditor

How can I handle the case where a class follows CamelCase, and a sub-property follows SnakeCase?

(my guess as to why they use both is that perhaps the SnakeCase come from older API code)

c# json json.net system.text.json