title: Retrofit 2 - Post FieldMap with Body Object
body: <p>I want to post a HashMap and a Object using Retrofit.
  I tried this code below but received <code>IllegalArgumentException</code>.</p>
  
  <pre><code>@POST("update")
  Call&lt;RSP010&gt; postApi010(@FieldMap HashMap&lt;String, String&gt; defaultData, @Body User user);
  </code></pre>
  
  <p>Logcat</p>
  
  <pre><code>java.lang.IllegalArgumentException: @FieldMap parameters can only be used with form encoding. (parameter #1)
  </code></pre>
  
  <p>But when I add <code>@FormUrlEncoded</code>. It said </p>
  
  <pre><code>java.lang.IllegalArgumentException: @Body parameters cannot be used with form or multi-part encoding. (parameter #2)
  </code></pre>
  
  <p><strong>UPDATE CODE</strong></p>
  
  <pre><code>public static HashMap&lt;String, String&gt; defaultData(){
      HashMap&lt;String, String&gt; map = new HashMap&lt;&gt;();
      map.put("last_get_time", String.valueOf(SharedPreferencesHelper.getLongValue(AppConstants.LAST_GET_UPDATE)));
      map.put("duid", SharedPreferencesHelper.getStringValue(AppConstants.DUID));
      return map;
  </code></pre>
  
  <p>My Object which I want to post</p>
  
  <pre><code>int profile_id;
  private String name;
  private String name_kana; // あいうえお
  private int gender; // 1 nam 2 nu
  private String birth_day;
  private String birth_time;
  private String birth_place;
  private String relationship;
  </code></pre>
  
  <p>Explain:</p>
  
  <p>I want to post multiple variables via API to server. FieldMap <code>defaultData</code> for default variables I want to use in every API.</p>
  
  <p><a href="https://futurestud.io/tutorials/retrofit-send-objects-in-request-body" rel="nofollow noreferrer">https://futurestud.io/tutorials/retrofit-send-objects-in-request-body</a> I've read this, it said instead of posting all separate variables of an object, I can post an object directly.</p>