title: Web Api 2 with OData v4 - Bound function returning complex object
body: <p>In this simple example I am trying to get an object serialized as JSON from a Web Api 2 + OData v4 service. Controller has bound function Test which is returning an array of annon. objects.</p>
  
  <pre><code>public class ProductsController : ODataController
  {
      [HttpGet]
      public IHttpActionResult Test(int key)
      {
          var res = new[]
          {
              new { Name = "a", Value = new[] { 1, 2, 3 } },
              new { Name = "b", Value = new[] { 2, 4, 5 } }
  
              // this also produces same result
              // new { Name = "a", Value = "c" },
              // new { Name = "b", Value = "c" }
          };
  
          return this.Ok(res);
      }
  }
  </code></pre>
  
  <p>Edm is built with this piece of code:</p>
  
  <pre><code>ODataModelBuilder builder = new ODataConventionModelBuilder();
  
  builder.EntitySet&lt;Product&gt;("Products");
  var productType = builder.EntityType&lt;Product&gt;();
  
  var f = productType.Function("Test").Returns&lt;object&gt;();
  </code></pre>
  
  <p>when I make a request to the service (eg. <a href="http://localhost:9010/odata/Products(33)/Default.Test" rel="nofollow">http://localhost:9010/odata/Products(33)/Default.Test</a>) I am getting a strange response - an array of two empty objects, like this:</p>
  
  <pre><code>{
    "@odata.context": "http://localhost:9010/odata/$metadata#Collection(System.Object)",
    "value": [
      {},
      {}
    ]
  }
  </code></pre>
  
  <p>In my real app I'm returning object serialized to a JSON string with Newtonsoft's Json converter - that works fine, but this problem is still bothering me. I suspect it is something related to OData's default serializer, but it is unclear to me how to configure it.</p>
  
  <p><strong>So, is it possible to configure edm function's return parameter in such way where I would get correctly serialized complex object?</strong></p>
  
  <p>Thanks!</p>