I use Retrofit 2.0.0-beta2 and 2.0.0-beta3.
If I POST data to my Backend the JSON String will escaped with backslashes and starts/ends with an ".
@Multipart
@POST("upload")
Call<JSONObject> upload(@PartMap Map<String,RequestBody> files,
@Part("version") String version,
@Part("data") String data // <-- JSON String
);
My JSON String...
{"foo":"kit","bar":"kat"}
... will transformed after POST with retrofit to
"{\"foo\":\"kit\",\"bar\":\"kat\"}"
In my backend I have to remove all backslashes and the first/last Character. Then I can use the JSON_decode function in PHP.
If I use @FormUrlEncoded instead of Multipart without sending any files everything works fine, but I need to POST files.
Is there any solution? Retrofit should POST the RAW JSON String.
You need to either:
RequestBody for a raw valueScalarsConverterFactory (from the converters-scalars module) before the JSON converter factory on your Retrofit.Builder for String support.Right now the String is being passed through your JSON converter and being escaped into a JSON string.
Most helpful comment
You need to either:
RequestBodyfor a raw valueScalarsConverterFactory(from the converters-scalars module) before the JSON converter factory on yourRetrofit.BuilderforStringsupport.Right now the
Stringis being passed through your JSON converter and being escaped into a JSON string.