title: Asp.NET Core API - Change field names
body: <p>How can API return customised names?</p>
  
  <p>For example:</p>
  
  <pre><code>&lt;UserInfo&gt;
      &lt;name&gt;aaaaaa&lt;/name&gt;
      &lt;endpoints&gt;
          &lt;int&gt;1&lt;/int&gt;
          &lt;int&gt;2&lt;/int&gt;
      &lt;/endpoints&gt;
  &lt;/UserInfo&gt;
  </code></pre>
  
  <p>is generated from code</p>
  
  <pre><code>public class UserInfo
  {
      public string name;
      public int[] endpoints;
  }
  </code></pre>
  
  <p>I'd like to return this:</p>
  
  <pre><code>&lt;User name="aaaaaa"&gt;
      &lt;endpoints&gt;
           &lt;endpoint&gt;1&lt;/endpoint&gt;
           &lt;endpoint&gt;2&lt;/endpoint&gt;
      &lt;/endpoints&gt;
  &lt;/User&gt;
  </code></pre>
  
  <p>How can I</p>
  
  <ol>
  <li>Rename UserInfo to User</li>
  <li>Define name as attribute</li>
  <li>Rename fields in endpoints array to <code>endpoint</code>?</li>
  </ol>
  
  <p>I've tried using <code>[DataContract]</code> and <code>[DataMember]</code>, but nothing changed.</p>
  
  <p>EDIT: Method I use to get output:</p>
  
  <pre><code>    // GET api/info
      [HttpGet("info")]
      public IActionResult GetInfo([FromHeader] string auth)
      {
          if (HasAccess(auth, Endpoints.Info))
          {
              return new ObjectResult(Database.GetInfoAboutUser(auth));
          }
          else
          {
              return Unauthorized();
          }
      }
  </code></pre>