Why JsonNull in GSON?
<p>The docs say the <a href="https://google.github.io/gson/apidocs/com/google/gson/JsonObject.html#get-java.lang.String-" rel="noreferrer">JsonObject#get</a> method returns null if no such member exists. That's not accurate; sometimes a <code>JsonNull</code> object is returned instead of <code>null</code>. </p>

<p>What is the idiom for checking whether a particular field exists in GSON? I wish to avoid this clunky style:</p>

<pre><code>jsonElement = jsonObject.get("optional_field");
if (jsonElement != null &amp;&amp; !jsonElement.isJsonNull()) {
    s = jsonElement .getAsString();
}
</code></pre>

<p>Why did GSON use <code>JsonNull</code> instead of <code>null</code>?</p>

<p>There is an answer for <a href="https://stackoverflow.com/a/6256907/519951"><strong>what</strong></a> are the differences between <code>null</code> and <code>JsonNull</code>. In my question above, I'm looking for the reasons why.</p>