I am using ASP.NET Core 3.1 Web API. I have the following response model:
public class UserModel
{
public string UserId { get; set; }
public string UserName { get; set; }
}
It produces the following json response:
{
"userId": 1,
"userName": "SomeName"
}
I am interested in is there any way to change the property names of output JSON without creating a new class? Also, I would like to apply this rule only for specific action and keep default property names for other actions. In our project, we stick to System.Text.Json Serializer. The desired JSON output:
{
"teacherId": 1,
"teacherName": "SomeName"
}
TeacherModel- a teacher is more specific than a user, and so they represent different things.