I'm moving a .Net Framework WebAPI to .Net Core. With Framework (notably using Newtonsoft.Json), a class or a struct is returned as xml or json according to the Accept header.
With .Net Core, structs are always coming back as empty json: e.g. [{},{}].
Starting from a pared down new project (i.e. WeatherController), how do I get this to properly serialize and return non-empty json?
public struct MyStructure
{
public double A;
public double B;
}
[ApiController]
[Route("[controller]")]
public class MyStructureController : ControllerBase
{
[HttpGet]
public IEnumerable<MyStructure> Get()
{
return new List<MyStructure>
{
new MyStructure(){A = 1.2d, B = 5.6d},
new MyStructure(){A = 2.2d, B = 3.3d},
};
}
}
//desired response: [{"X":1.2,"Y":5.6},{"X":2.2,"Y":3.3}]
I'm not finding what I need in the supported, nor the unsupported, serialization documentation but I'm clearly overlooking something!