title: Convert List<Object> to ByteArray
body: <p>Currently, I'm sending my objects from server side to client side using JsonResults.</p>
  <p>The current code is as follows:</p>
  <pre><code>[HttpGet]
      public JsonResult Get()
      {
          //Create a List object, categoryList which can store anonymous objects later.
          List&lt;object&gt; categoryList = new List&lt;object&gt;();
  
          var categoriesQueryResult = Database.Categories
                   .Where(eachCategory =&gt; eachCategory.DeletedAt == null)
                   .Include(eachCategory =&gt; eachCategory.CreatedBy)
                   .Include(eachCategory =&gt; eachCategory.UpdatedBy);
  
          //Loop through each Category entity in  the categoriesQueryResult's and add it into categoryList
          foreach (var oneCategory in categoriesQueryResult)
          {
              categoryList.Add(new
              {
                  categoryId = oneCategory.CategoryId,
                  categoryName = oneCategory.CategoryName,
                  visibility = oneCategory.Visibility,
                  displayStart =  oneCategory.DisplayStart,
                  displayEnd = oneCategory.DisplayEnd,
                  createdAt = oneCategory.CreatedAt,
                  updatedAt = oneCategory.UpdatedAt,
                  createdBy = oneCategory.CreatedBy.FullName,
                  updatedBy = oneCategory.UpdatedBy.FullName,
                  isSpecial = oneCategory.IsSpecial
  
              });
          }//end of foreach
  
          return new JsonResult(categoryList);
      }// end of get
  </code></pre>
  <p>So what I would like to do now is to convert the List to a ByteArray and then return the converted object to the client side as a ByteArray.</p>
  <p>I've tried:</p>
  <pre><code>[HttpGet]
      public byte[] Get()
      {
          //Create a List object, categoryList which can store anonymous objects later.
          List&lt;object&gt; categoryList = new List&lt;object&gt;();
  
          var categoriesQueryResult = Database.Categories
                   .Where(eachCategory =&gt; eachCategory.DeletedAt == null)
                   .Include(eachCategory =&gt; eachCategory.CreatedBy)
                   .Include(eachCategory =&gt; eachCategory.UpdatedBy);
  
          //Loop through each Category entity in  the categoriesQueryResult's and add it into categoryList
          foreach (var oneCategory in categoriesQueryResult)
          {
              categoryList.Add(new
              {
                  categoryId = oneCategory.CategoryId,
                  categoryName = oneCategory.CategoryName,
                  visibility = oneCategory.Visibility,
                  displayStart =  oneCategory.DisplayStart,
                  displayEnd = oneCategory.DisplayEnd,
                  createdAt = oneCategory.CreatedAt,
                  updatedAt = oneCategory.UpdatedAt,
                  createdBy = oneCategory.CreatedBy.FullName,
                  updatedBy = oneCategory.UpdatedBy.FullName,
                  isSpecial = oneCategory.IsSpecial
  
              });
          }//end of foreach
          byte[] convertedObject = categoryList.OfType&lt;byte&gt;().ToArray();
  
          return convertedObject;
      }// end of get
  </code></pre>
  <p>But it does not seem to work.</p>