I have the following ASP.NET Core Controller:
using System.Text;
using Microsoft.AspNetCore.Mvc;
namespace FightClubApi.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class ProjectMayhemController : ControllerBase
{
[HttpGet]
public Member Get() =>
new Member
{
Name = "Robert Paulson",
Code = ASCIIEncoding.ASCII.GetBytes("His name was Robert Paulson")
};
}
public class Member
{
public string Name { get; set; }
public byte[] Code { get; set; }
}
}
Hitting that API endpoint (using GET https://localhost:5001/api/ProjectMayhem
) returns the following JSON:
{
"name": "Robert Paulson",
"code": "SGlzIG5hbWUgd2FzIFJvYmVydCBQYXVsc29u"
}
However, I would like the Member.Code
property to be serialized to a JavaScript Uint8Array
.
I could convert the Base64 encoded JSON property back to a Uint8Array
using something like:
code = new TextEncoder("utf-8").encode(atob(code));
, but I want to avoid doing it on the front-end.