Send a name/value pair as object in Multipart using Retrofit
<p>In my code I have to make a MultipartForm-Data PUT request to update an object in the server, it ought to be Multipart as it is possible the user will send an image together with the data.</p>

<p>In order to do that, I am currently using Retrofit since it's a library I'm decently used to and it's working to send images to the server.</p>

<p>However, things have changed server-side and now one of the parameters that must be sent is: </p>

<pre><code>{"step":
    {"type":"begin"}
}
</code></pre>

<p>However that's been proving to be surprisingly hard to do.</p>

<p>Things I have tried include passing it as a MultipartTypedOutput, a hand-typed String and a JSONObject converted to String, all of which gave me:</p>

<blockquote>
  <p>retrofit.RetrofitError: 400 Bad Request</p>
</blockquote>

<p>The URL being used is correct, I've double checked with the person who maintains the server and it is reaching the server, but with an incorrect "step" object.</p>

<p>I've also tried passing it as NameValuePair, Map and HashMap, all of which gave me:</p>

<blockquote>
  <p>retrofit.RetrofitError: Part body must not be null.</p>
</blockquote>

<p>@FieldPart which looks to be perfect for this isn't compatible with Multipart, so is there a way to do this with Retrofit at all? </p>

<p>My current PUT method is as such:</p>

<pre><code>@Headers({
    "Connection: Keep-Alive",
    "Accept-Language: en-US"
})
@Multipart
@PUT("/0.1/user/{id}")
String updateUser(@Path("id") String userId, @Part("step") Map&lt;String,String&gt; type);
</code></pre>

<p>Where the Map type has been changed to all the types I mentioned before.</p>