Communicating with backend in JSON can be challenging.
In case of C# model which by convention should be in CamelCase notation and backend which is using snake_notation we can easily solve the problem with Json.NET.
For example, we have the next model:
and we want it to be serialised to: { “foo_bar”: “” }
We could use an attribute:
That will work, however, if we want to generalise this strategy we should create a JsonSerializerSettings with DefaultContactResolver which is using SnakeCaseNamingStrategy and to use it while serialisation/deserialization:
Using the JsonConverter globally will solve the different notation problem.