title: retrofit map as body - how to post map with inner json object
body: <p>Retrofit2 how would i POST using a map json body that has inner json. Let me show you an example: </p>
  
  <pre><code>{
      "id_invoice": 1234,
      "action": "viewed",
      "data": {
          "id_object": 88,
          "id_store": 43,
          "type": "payment"
       }
  }
  </code></pre>
  
  <p>Notice how the "data" JSON object has inner JSON.  How can I put all this into a map so, I can send it to retrofit using the following service endpoint:</p>
  
  <pre><code>public interface Api {
      @NonNull
      @POST("cart/payment")
      @Headers({"Content-Type:application/json"})
      Observable&lt;ResponseBody&gt; postPaymentEvent(@Body Map&lt;String, Object&gt; body);
  }
  </code></pre>
  
  <p>I tried the following:</p>
  
  <pre><code>Map&lt;String, Object&gt; map = new HashMap&lt;&gt;();
  JSONObject json = new JSONObject();
  json.put("id_object", 88);
  json.put("id_store", 43);
  json.put("type", "payment");
  map.put("action", "view");
  map.put("id_invoice", 1234);
  map.put("data", json); //this is wrong. it creates the following response with a nameValuePairs field, which is not what i want:
  </code></pre>
  
  <blockquote>
    <p>Body:</p>
  </blockquote>
  
  <pre><code>{
      "action": "page_view",
      "id_invoice": "1234",
      "data": {
          "nameValuePairs": {
              "id_object": 88,
              "id_store": 43,
              "type": "view"
           }
      }
  }
  </code></pre>