I have several projects in my solution. Here are 2 of them:
- API (netcoreapp3.1 asp web API - hence System.Text.Json is available in it)
- Entities (netstandard2.0 class library - hence System.Text.Json is not available there).
Entities contains DTOs(Data Transfer Objects) for my API. I need to provide my own JSON field names for DTOs. I came across this question, so i tried to use JsonPropertyNameAttribute, which is provided by System.Text.Json (.net core 3) and it does not work.
What do i need to do to specify custom JSON field names? Change the Entities project type to netcoreapp3.1 (then there are problems with other .net standard 2.0 libraries)? Use a different way of specifying custom JSON field names for DTO (i do not want to use Newtonsoft.Json because i heard that it has compatibility issues with .net core 3+ asp web APIs)?
Update: As strickt01 pointed, there is NuGet package that provides System.Text.Json serialization and deserialization for other .net versions, such as:
- .NET Standard 2.0 and later
- .NET Framework 4.7.2 and later
- .NET Core 2.0, 2.1, and 2.2