title: Sending JSON to Firebase Cloud Messaging
body: <p>I'm trying to send a push notification to an Android device using Firebase Cloud Messaging.</p>
  
  <p>The JSON message <strong>does not work, and I'm getting a 400 response</strong>:</p>
  
  <blockquote>
    <p>{"to":"cXE06Grz67M:APA91bHoOc7pUPqKc9SMgCMKwH2s0r2zAyMac-LVjZVJiRLKSHCPVzi1K1tHmwq_Z35u8i32XL-cQKHGSWvzjD6ItvaMZh-LpRLHaz0iPQTMV-yQ6sqEHBjUvYkN3BDM4ftFowUs_L2p","data":"{\"PushMessage\":\"11\"}"}</p>
  </blockquote>
  
  <p><strong>It is the "data" part that is causing a problem.</strong></p>
  
  <p>The following - without the "data" part - <strong>works and I'm getting a 200 response</strong>:</p>
  
  <blockquote>
    <p>"to":"cXE06Grz67M:APA91bHoOc7pUPqKc9SMgCMKwH2s0r2zAyMac-LVjZVJiRLKSHCPVzi1K1tHmwq_Z35u8i32XL-cQKHGSWvzjD6ItvaMZh-LpRLHaz0iPQTMV-yQ6sqEHBjUvYkN3BDM4ftFowUs_L2p"}</p>
  </blockquote>
  
  <p>What's wrong with the JSON format? And how can I fix it?</p>
  
  <p>Specifically, the "data" part is generated from (server-side code is in Java):</p>
  
  <pre><code>HashMap&lt;String, String&gt; dataMessages = new HashMap&lt;&gt;();
  dataMessages.put("PushMessage", Integer.toString(pushMessage));
  ...
  Type stringStringMap = new TypeToken&lt;Map&lt;String, String&gt;&gt;() {
  }.getType();
  Gson gson = new Gson();
  String dataMessageString = gson.toJson(dataMessages, stringStringMap);
  ...
  JsonObject jsonObject = new JsonObject();
  ...
  jsonObject.addProperty("data", dataMessageString);
  ...
  </code></pre>