I'm migrating an old API to .net core web api and one of the responses includes the same value twice, so I'm using the native Json library of .NET 5 and I'm trying to get the same value twice in the JSON response, 'Id' and 'id'
{
...
"Id": "10",
"id": "10"
...
}
In my Startup, ConfigurationServices I configured the Json Option like this:
services.AddControllers().AddJsonOptions(options =>
{ options.JsonSerializerOptions.PropertyNameCaseInsensitive = true; });
My action method
[HttpGet]
public async Task<ActionResult<IEnumerable<object>>> GetContacts(string projectID)
{
Project project = _context.Projects.Where(a => a.Name == projectID)
.FirstOrDefault();
var contacts = await _context.Contacts.Where(a => a.ProjectId == project.Id)
.Select(o => new { id = o.Id, ID = o.Id}).ToListAsync();
return contacts;
}
While serializing, I am getting the "The JSON property name for collides with another property." I think I'm missing something, and I'm stuck in this.
PropertyNameCaseInsensitive = true
? – Anglomania