title: How to extract the data in a java.util.Map object?
body: <p>In the <a href="https://firebase.google.com/docs/cloud-messaging/android/receive#override-onmessagereceived" rel="nofollow noreferrer">Firebase documentation</a>, there is this code sample:</p>
  
  <pre><code>public void onMessageReceived(RemoteMessage remoteMessage) {
    if (remoteMessage.getData().size() &gt; 0) {
      Log.d(TAG, "Message data payload: " + remoteMessage.getData());
    }
  }
  </code></pre>
  
  <p>Android Studio tells me that <code>remoteMessage.getData()</code> returns a type of <code>java.util.Map</code>. The data at the sending end is in Json format, and if the data sent is <code>{"a":"b","c":"d"}</code>, <code>remoteMessage.getData().toString()</code> will produce:</p>
  
  <pre><code>{a=b, c=d}
  </code></pre>
  
  <p>I am very new to Java. How do I access the data returned in <code>getData()</code>, even if I know the Json structure that is used?</p>
  
  <p>I tried:</p>
  
  <pre><code>HashMap&lt;String, String&gt; Data = (HashMap&lt;String,String&gt;)remoteMessage.getData();
  </code></pre>
  
  <p>but I got the following run-time exception:</p>
  
  <blockquote>
    <p>android.support.v4.util.Array.Map cannot be cast to java.util.HashMap.</p>
  </blockquote>