title: WebApi Put how to tell not specified properties from specified properties set to null?
body: <p>Here is the scenario. There is an web api put call to change an object in sql server database. We want only to change the fields on the database object if they were explicitly specified on webapi call json. For example:</p>
  
  <pre><code>{ "Name":"newName", "Colour":null }
  </code></pre>
  
  <p>That should change the Name field to "newName" and "Colour" field to null. As opposed to this json:</p>
  
  <pre><code>{ "Name":"newName" }
  </code></pre>
  
  <p>that should only change the Name field, leaving the old Colour value intact.</p>
  
  <p>What is a good way with WebApi to detect whether a property was passed or not?</p>
  
  <p>If I define my method like this:</p>
  
  <pre><code>[HttpPut]
  [Route("/item/{id}")]
  public void ChangeItem(int id, Item item)
  {
      ...
  }
  </code></pre>
  
  <p><code>item.Colour</code> will be null in either case. Note, that I'm working with a variety of data types here and property <code>Colour</code> in the example could be <code>int</code>, <code>string</code>, <code>DateTime</code>, <code>Guid</code>, etc. </p>
  
  <p>I understand that I can get the raw json with <code>[FromBody]</code> attribute and then parse it myself, but it seems that the default binder is already doing most of the work (including validation), so I would be curious how I could reuse it, but also achieve what I want. What is the easiest way?</p>
  
  <p><strong>Update</strong>:</p>
  
  <p>I'd like to clarify that mine is an "occasionally connected" scenario. That is, the devices that are using the API are out of network coverage most of the time, and they sync using the API from time to time.</p>
  
  <p>Practically this means that most of the data that is needed to sync are aggregated into zero or one "push updates to server" call followed by "get latest state from server" call. With Sql Server and EF in the back-end that leads to several different (and sometimes unrelated) entities are contained within single json. Eg:</p>
  
  <pre><code>class TaskData
  { 
      public IList&lt;User&gt; AssignedUsers {get; set;} 
      public IList&lt;Product&gt; Products {get; set;} 
      public Task Task {get; set}
  }
  </code></pre>
  
  <p>Also the model classes that are used to generate json for GET calls are separate from EF Entites, as the database schema does not exactly match the API object model.</p>