title: Gson deserialization: How to distinguish between fields that are missing and fields that are explicitly set to null?
body: <p>I'm trying to implement <a href="https://www.rfc-editor.org/rfc/rfc7396" rel="nofollow noreferrer">JSON Merge Patch</a> for a Java (JAX-RS) webservice I'm building.</p>
  <p>The gist is that partial updates of a record are done by sending a JSON document to the server that only contains the fields that should be changed.</p>
  <p>Given this record</p>
  <pre><code>{
    &quot;a&quot;: &quot;b&quot;,
    &quot;c&quot;: {
      &quot;d&quot;: &quot;e&quot;,
      &quot;f&quot;: &quot;g&quot;
    }
  }
  </code></pre>
  <p>, the following JSON update document</p>
  <pre><code>{
    &quot;a&quot;:&quot;z&quot;,
    &quot;c&quot;: {
      &quot;f&quot;: null
    }
  }
  </code></pre>
  <p>should set a new value for <code>&quot;a&quot;</code>  and delete <code>&quot;f&quot;</code> inside <code>&quot;c&quot;</code>.</p>
  <p><strong>The latter is the problem. I don't know how I can distinguish between an input where f is missing and an input where f is null.</strong> Both, as far as I can tell, would be deserialized to <code>null</code> in the target Java Object.</p>
  <p>What do?</p>