ASP.NET Core MVC serializes responses returned from my Microsoft.AspNetCore.Mvc.ControllerBase controller methods.
So the following will serialize a MyDTO object to JSON:
[Produces("application/json")]
[HttpGet]
public MyDTO test()
{
return new MyDTO();
}
However, I want to use the exact same serializer within the method itself. Is that possible? Something like
[Produces("application/json")]
[HttpGet]
public MyDTO test()
{
var result = new MyDTO();
string serialized = this.<SOMETHING GOES HERE>(result);
Console.WriteLine($"I'm about to return {serialized}");
return result;
}
It's important that it's the same serializer, including any options set in the stack.