retrofit2

Retrofit 2: How to set individual timeouts on specific requests?

会有一股神秘感。 提交于 2021-01-21 03:33:54
问题 I have set a global timeout in my Retrofit adapter by doing OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setReadTimeout(20, TimeUnit.SECONDS); okHttpClient.setConnectTimeout(20, TimeUnit.SECONDS); retrofit = new Retrofit.Builder() .client(okHttpClient) .build(); Great! But I would like to set an specific timeout for certain requests E.g. public interface MyAPI { @GET() Call<Void> notImportant (@Url String url); @GET Call<Void> veryImportant(@Url String url); So veryImportant

Retrofit 2: How to set individual timeouts on specific requests?

痴心易碎 提交于 2021-01-21 03:32:12
问题 I have set a global timeout in my Retrofit adapter by doing OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setReadTimeout(20, TimeUnit.SECONDS); okHttpClient.setConnectTimeout(20, TimeUnit.SECONDS); retrofit = new Retrofit.Builder() .client(okHttpClient) .build(); Great! But I would like to set an specific timeout for certain requests E.g. public interface MyAPI { @GET() Call<Void> notImportant (@Url String url); @GET Call<Void> veryImportant(@Url String url); So veryImportant

how to upload image in latest retrofit version using Kotlin with the right RequestBody.create method?

倖福魔咒の 提交于 2021-01-07 06:59:38
问题 I have tried to read the solution in here or in here , but I am confused when I implement it on my own code I am using this on my gradle implementation 'com.squareup.retrofit2:retrofit:2.5.0' implementation 'com.squareup.retrofit2:converter-gson:2.5.0' implementation 'com.squareup.okhttp3:logging-interceptor:4.4.0' I am trying to upload an image using this code in retorift interface UploadMediaAPI { @Multipart @POST("uploadImage") fun uploadImage( @Part image: MultipartBody.Part ): Call

how to upload image in latest retrofit version using Kotlin with the right RequestBody.create method?

江枫思渺然 提交于 2021-01-07 06:59:06
问题 I have tried to read the solution in here or in here , but I am confused when I implement it on my own code I am using this on my gradle implementation 'com.squareup.retrofit2:retrofit:2.5.0' implementation 'com.squareup.retrofit2:converter-gson:2.5.0' implementation 'com.squareup.okhttp3:logging-interceptor:4.4.0' I am trying to upload an image using this code in retorift interface UploadMediaAPI { @Multipart @POST("uploadImage") fun uploadImage( @Part image: MultipartBody.Part ): Call

PUT Request for Json with Json array inside

回眸只為那壹抹淺笑 提交于 2021-01-07 02:39:45
问题 I'm trying to update a PUT request which has a JSONArray inside it and I'm constantly getting a 500 error response. Here how the api structure is: { "imei": 514515854152463, "franquia": "SAO", "sistema": "PEGASUS", "lista": 2055313, "entregas":[ { "codHawb": "02305767706", "dataHoraBaixa": "2020-12-03T15:26:22", "foraAlvo": 1000, "latitude": 44.4545, "longitude": 45.545, "nivelBateria": 98, "tipoBaixa": "ENTREGA" } ] } I've tried the api in Postman to see if its working and it is. But when I

Not able to make @Post request using retrofit2 in android

你离开我真会死。 提交于 2021-01-04 06:42:11
问题 I am learning how to use retrofit in android but whenever I try to retrieve data from the internet my app doesn't return anything My response doesn't come successful and I don't know how to fix the error currently I am trying to post and retrieve data from this URL using https://jsonplaceholder.typicode.com. I am unable to figure out what is causing this. MainActivity private void createpost() { Post post2=new Post(1,"This is Title","10"); Call<Post> postCall= mWebService.createPost(post2);

Unable to create call adapter for retrofit2.Response<…>

让人想犯罪 __ 提交于 2020-12-12 12:19:19
问题 My Api: @GET("/cinema/notShownMovies") fun getNotShownMovies( @Query("token") token: String ): Response<GetMovieResponse> @JsonClass(generateAdapter = true) data class Movie( val id: Long, val name: String, val date: String, @field:Json(name = "trailer_link") val trailerLink: String?, @field:Json(name = "poster_link") val posterLink: String?, @field:Json(name = "booked_tickets") val bookedTickets: Int, @field:Json(name = "movie_year_id") val movieYearId: Int, @field:Json(name = "created_at")

Exclude a Kotlin data class property/field from serialization/deserialization using gson

拥有回忆 提交于 2020-12-10 02:37:20
问题 I am trying to exclude a Kotlin property from deserialization using gson. I have tried different methods from annotating the property with @Transient to creating a custom annotation strategy (specifying the strategy in the gson builder of course), but nothing seems to be working, as the property keeps getting null instead of the value I initialized the property with. I have not tried using the @Expose annotation, but I do not want to annotate other fields with @Expose Please, how can I

Exclude a Kotlin data class property/field from serialization/deserialization using gson

末鹿安然 提交于 2020-12-10 02:35:06
问题 I am trying to exclude a Kotlin property from deserialization using gson. I have tried different methods from annotating the property with @Transient to creating a custom annotation strategy (specifying the strategy in the gson builder of course), but nothing seems to be working, as the property keeps getting null instead of the value I initialized the property with. I have not tried using the @Expose annotation, but I do not want to annotate other fields with @Expose Please, how can I