title: How can I serialize an object but have a given property remain serialized to a byte array?
body: <p>I have the following ASP.NET Core Controller:</p>
  
  <pre class="lang-cs prettyprint-override"><code>using System.Text;
  using Microsoft.AspNetCore.Mvc;
  
  namespace FightClubApi.Controllers
  {
      [ApiController]
      [Route("api/[controller]")]
      public class ProjectMayhemController : ControllerBase
      {
          [HttpGet]
          public Member Get() =&gt;
              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; }
      }
  }
  </code></pre>
  
  <p>Hitting that API endpoint (using <code>GET https://localhost:5001/api/ProjectMayhem</code>) returns the following JSON:</p>
  
  <pre><code>{
    "name": "Robert Paulson",
    "code": "SGlzIG5hbWUgd2FzIFJvYmVydCBQYXVsc29u"
  }
  </code></pre>
  
  <p>However, I would like the <code>Member.Code</code> property to be serialized to a JavaScript <code>Uint8Array</code>.</p>
  
  <p>I could convert the Base64 encoded JSON property back to a <code>Uint8Array</code> using something like:</p>
  
  <pre class="lang-js prettyprint-override"><code>code = new TextEncoder("utf-8").encode(atob(code));
  </code></pre>
  
  <p>, but I want to avoid doing it on the front-end.</p>