gson handle: Expected BEGIN_OBJECT but was BEGIN_ARRAY
<p>I am using Retrofit and <code>Gson</code> to make API calls. I have a problem with responses from server. For some attributes it is sending empty  <code>JSONArray</code> instead of null <code>JSONObject</code>. e.g.:</p>

<p>in normal situation:</p>

<pre><code>  {
    "pagination": { 
      "links": {
        "next": "http://api.com/nextlink"
      } 
    }
  } 
</code></pre>

<p>but sometimes when the "links" is empty, the server sends me this:</p>

<pre><code>  {
    "pagination": { 
      "links": []
    }
  } 
</code></pre>

<p>which cause <code>java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY</code>.</p>

<p>I know that I can handle it with using custom <code>JsonDeserializer</code> for object "Pagination" and <code>registerTypeAdapter</code> when creating <code>GsonBuilder</code>.</p>

<p>But my question is: It is possible to handle this cases in general for all responses? I don't have access to API so I cannot change it and I don't know for which attributes I can get empty <code>JSONArray</code> instead of <code>JSONObject</code> that is expected.</p>

<p>Thank you. </p>