retrofit2

Using @FieldMap and @Part in single request in Retrofit2 gets java.lang.IllegalArgumentException: Only one encoding annotation is allowed.for method

旧时模样 提交于 2019-12-01 12:00:24
This might seem similar to earlier questions but none actually answers my question. I need to Post multiple fields and multiple images in one request using retrofit2 and i'm getting this error java.lang.IllegalArgumentException: Only one encoding annotation is allowed.for method xxx i'm using @Multipart @FormUrlEncoded since @Field requires @FormUrlEncoded and @Part requires @Multipart. the more logical thing to do is to remove the @FormUrlEncoded annotation, but how do i go from there. Now the question is how do i go about the task to achieve sending my post in a single request. here's the

Retrofit 2: How to handle dynamic response

落花浮王杯 提交于 2019-12-01 11:29:15
I am trying fetch data from this api: http://www.omdbapi.com/ I am using Retrofit 2 and created a pojo for first json. The thing I am curious about is how to convert my pojo to second one when data is not available. When there is data available, It returns this json: http://www.omdbapi.com/?t=Suits { Title: "Suits", Year: "2011–", Rated: "TV-14", Released: "23 Jun 2011", Runtime: "44 min", Genre: "Comedy, Drama", Director: "N/A", Writer: "Aaron Korsh", Actors: "Gabriel Macht, Patrick J. Adams, Rick Hoffman, Meghan Markle", Plot: "On the run from a drug deal gone bad, Mike Ross, a brilliant

Retrofit2 Post body as Json

只谈情不闲聊 提交于 2019-12-01 10:30:24
I was updating Retrofit to use Retrofit2 and I already managed to a lot of things GET, POST, PUT... But i had a request that i have to send a whole JSON I managed to do it in Retrofit 1.9 but in Retrofit2 there is no support for it. import retrofit.mime.TypedString; public class TypedJsonString extends TypedString { public TypedJsonString(String body) { super(body); } @Override public String mimeType() { return "application/json"; } } How to make it retrofit2 ? You can literally just force the Header to be application/json (as you've done) and send it as a string... .. Call call = myService

Send Image file via Retrofit from Android to Spring

隐身守侯 提交于 2019-12-01 09:54:06
问题 I am trying to upload Image via Retrofit to S3 via Spring. So, it's basically 2 tasks. Pass Image to Spring API From Spring API upload it to S3 Server. I know how to upload the Image to S3 and it works fine. My Problem is the first part. I have tried many solutions on net but didn't work.Here's my code -> On Android side, first I am Getting file and Uploading it to Spring API -> private void UploadFiles() { File uploadFile = fileArrayList.get(0); if (uploadFile != null) { Log.d(TAG,

Retrofit2 Post body as Json

烈酒焚心 提交于 2019-12-01 09:06:28
问题 I was updating Retrofit to use Retrofit2 and I already managed to a lot of things GET, POST, PUT... But i had a request that i have to send a whole JSON I managed to do it in Retrofit 1.9 but in Retrofit2 there is no support for it. import retrofit.mime.TypedString; public class TypedJsonString extends TypedString { public TypedJsonString(String body) { super(body); } @Override public String mimeType() { return "application/json"; } } How to make it retrofit2 ? 回答1: You can literally just

Using @FieldMap and @Part in single request in Retrofit2 gets java.lang.IllegalArgumentException: Only one encoding annotation is allowed.for method

左心房为你撑大大i 提交于 2019-12-01 09:03:00
问题 This might seem similar to earlier questions but none actually answers my question. I need to Post multiple fields and multiple images in one request using retrofit2 and i'm getting this error java.lang.IllegalArgumentException: Only one encoding annotation is allowed.for method xxx i'm using @Multipart @FormUrlEncoded since @Field requires @FormUrlEncoded and @Part requires @Multipart. the more logical thing to do is to remove the @FormUrlEncoded annotation, but how do i go from there. Now

Runtime Execption java.lang.NoClassDefFoundError: retrofit2.Platform in Android

元气小坏坏 提交于 2019-12-01 06:05:10
i am using Rtofit to handling the Serverside Data from Mobile After Implementing the Retrofit I am Getting the below Exception any know about this issue tell me where i am did wrong Init Retrofit: mRetrofit = new Retrofit.Builder() .baseUrl(AppConstance.APP_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); Iservice = mRetrofit.create(IdeaService.class); Gradle File dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.2.1' compile 'com.squareup.retrofit2:retrofit:2.0.2' compile 'com.squareup

Is it possible to send a String[] through Multipart using Retrofit?

故事扮演 提交于 2019-12-01 05:25:15
I'm developing an application where at a point the user has to choose any number of countries from a list and I must send the selected names through a multipart. I am not uploading any file along with the String[], but there is no route to upload information without it being a multipart and I don't have any saying in how the web server operates. I've attempted to simply send it as an Array, ArrayList and JsonArray as such: @Headers({ "Connection: Keep-Alive", }) @Multipart @PUT("/user/{id}") String updateUser(@Path("id") int userId, @Part("user[countries]") String[] countries); I've also

Fetching json object and array from retrofit

此生再无相见时 提交于 2019-12-01 04:43:49
I want to fetch json from [this link][1]: https://api.myjson.com/bins/38ln5 using retrofit sample json is { "students": [ { "id": "1", "name": "Larzobispa" }, { "id": "2", "name": "La Cibeles" } ] } Please explain details how to do that. Thanks a lot, guys! Retrofit will automatically parse JSON Object as well JSON Array. @GET("/register?email=example@123.com") public void responseString(Callback<Student> response); your model class looks like: public class Student{ private ArrayList<StudentInfo> studentList = new ArrayList<>(); //getter and setters } public class StudentInfo{ private String

HttpLoggingInterceptor for http request & response logging

我只是一个虾纸丫 提交于 2019-12-01 04:20:31
问题 I'm using retrofit2 and I need to log all request and response. Request and response works perfectly, All I need is to log those request/response, I tried almost every solution, which I found here, but did not find solution. I don't understand what's wrong is here this is my code class Factory { private final static OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); private static NetworkApi.Factory serverApi; private static HttpLoggingInterceptor interceptor = new