title: Using Automapper to map from dynamic/JObject to arbitrary types without creating multiple maps
body: <p>In an ASP.NET Core controller method, which has a parameter of type <code>dynamic</code>, I would like to map using Automapper as shown below. The method looks like this:</p>
  
  <pre><code>public IActionRsult Post([FromBody] dynamic model) {
    // Skip validation
    switch(model.src) {
      case "employer"
        var employerVM = _mapper.Map&lt;EmployerViewModel&gt;(model.data);
        // Work with mapped object
      break;
      case "employee"
        var employeeVM = _mapper.Map&lt;EmployeeViewModel&gt;(model.data);
        // Work with mapped object
      break;
    }
  }
  </code></pre>
  
  <p>where <code>EmployerViewModel</code> looks like this:</p>
  
  <pre><code>public class EmployerViewModel {
     public string CompanyName {get; set;}
     public string CompanyAddress {get; set;}
  }
  </code></pre>
  
  <p>and <code>EmployeeViewModel</code> looks like this:</p>
  
  <pre><code>public class EmployeeViewModel {
     public string FirstName {get; set;}
     public string LastName {get; set;}
     public bool Ready {get; set;} 
  }
  </code></pre>
  
  <p>It receives JSON data from the client side, which may look like this:</p>
  
  <pre><code>{
    "src": "employer",
    "data": {
      "CompanyName": "Pioneers Ltd.",
      "CompanyAddress": "126 Schumacher St., London" 
    }
  }
  </code></pre>
  
  <p>or this: </p>
  
  <pre><code>{
    "src": "employee",
    "data": {
      "FirstName": "John",
      "LastName": "Doe",
      "Ready": true
    }
  }
  </code></pre>
  
  <p>Now everything works fine except for boolean properties, which are always set to false no matter what the value in JSON is. I have JSON input formatter, which constructs the instances in the parameter. I've checked the type of the instances and found them to be Newtonsoft.Json.Linq.JObject </p>
  
  <p>Any idea how I can get bools to behave correctly?</p>
  
  <p>I would like to continue supporting mapping an arbitrary number of destination classes using the <code>TDestination IMapper.Map&lt;TDestination&gt;(object source)</code> (see <a href="https://github.com/AutoMapper/AutoMapper/blob/master/src/AutoMapper/IMapper.cs#L14" rel="nofollow noreferrer">here</a>) without having to explicitly construct AutoMapper maps for each. Any hint how this can be achieved?</p>
  
  <p>P.S. I'm using AutoMapper 6.2.1 and ASP.NET Core 1.1.3</p>