retrofit

Retrofit2.0 using with rxjava will do costly reflection in mian thread even using subscribeOn()

元气小坏坏 提交于 2019-12-12 18:27:50
问题 Retrofit interface that return observable interface WeatherApi { companion object { val HOST = "https://api.heweather.com/x3/" val KEY = "41054a8f1d1a4ac992b1683e47a50146" } @GET("weather") fun getWeather(@Query("city") city: String, @Query("key") key: String) : Observable<Weather> } RestApi: class RestApi { var weatherApi: WeatherApi init { val logInterceptor = HttpLoggingInterceptor() logInterceptor.level = HttpLoggingInterceptor.Level.BODY val okClient = OkHttpClient.Builder()

Android Retrofit Causes Socket Timeout Exception

时光毁灭记忆、已成空白 提交于 2019-12-12 15:53:14
问题 I am making a POST call to a tomcat server running Struts2 using the retrofit library on an Android Galaxy S3 (/Nexus 7) device. The POST call fails. The tomcat log shows Socket timeout exception. The same POST using the exact same headers done via curl does not have any issues. I verified that the data on the wire matches using charles proxy. Any tips/ideas on debugging this issue. The post call is as follows @POST(Constants.URL_GET_ORDER_LIST_BASE) void getCardOrderList(@Body

Retrofit - java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT

我与影子孤独终老i 提交于 2019-12-12 15:22:34
问题 I am trying to parse my own JSON, but getting JSONSyntaxException , here is how my JSON looks: { "type":"success", "value":[ { "id":1, "title":"Title - 1", "name":{ "first":"First - 1", "last":"Last - 1" }, "hobbies":[ "Writing Code - 1", "Listening Music - 1" ] }, ..... ] } Log says: E/app.retrofit_chucknorries.MainActivity$2: ERROR: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 7 column 12 path $.value[0].name 01-21

Retrofit get conversion error object

南笙酒味 提交于 2019-12-12 15:08:51
问题 I'm using Retrofit 1.9. I have a custom RetrofitErrorHandler extending ErrorHandler. I'm overriding handleError(RetrofitError cause) and I use cause.getKind() to find CONVERSION error. Is there a way to find which object failed to be unserialized? Example : I call the server to retrieve my user into a User POJO, but there is a conversion Error. I'd like to know that the conversion error is due to User. 来源: https://stackoverflow.com/questions/34896624/retrofit-get-conversion-error-object

Android retrofit parse nested json response in List

折月煮酒 提交于 2019-12-12 13:41:44
问题 I am creating a News API based Android application which loads the news of a particular channel say ABC News into MainFragment using a RecyclerView. I am making an API Call for that in MainFragment as follows: MainFragment.java public class MainFragment extends Fragment { protected RecyclerView recyclerView; protected NewsAdapter adapter; protected String API_KEY; String sourceTitle, sourceID; List<Articles> articleList; public MainFragment() { } @Nullable @Override public View onCreateView

Retrofit Method invocation may produce 'java.lang.NullPointerException'

让人想犯罪 __ 提交于 2019-12-12 12:17:37
问题 Using Retrofit 2.3.0 I am getting the following message in Android Studio Any suggestions on how I could remove this IDE error message. Thanks 回答1: From the Response documentation: @Nullable public T body() The deserialized response body of a successful response. This means that response.body() can return null, and as a result, invoking response.body().getItems() can throw a NullPointerException . To avoid the warning message, check that response.body() != null before invoking methods on it.

how to send JSONObject into retrofit API call android

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 12:01:28
问题 I have implemented first time retrofit in my android code and facing follwing issues getting following error : java.lang.IllegalArgumentException: @Body parameters cannot be used with form or multi-part encoding. (parameter #1) I have implemented my code like below public interface APIService { @FormUrlEncoded @POST("/") @Headers({ "domecode: axys", "Content-Type: application/json;charset=UTF-8" }) Call<JsonObject> sendLocation(@Body JsonObject jsonObject); } public class ApiUtils { static

RxJava and cursor based RESTful pagination

自闭症网瘾萝莉.ら 提交于 2019-12-12 10:46:46
问题 I'm working with the Spotify API and am hoping to chain a few paginated results using RxJava. Spotify uses cursor based pagination, so solutions like the one from @lopar will not work. The response is from this call and looks something like this (imagine there are 50 items ): { "artists" : { "items" : [ { "id" : "6liAMWkVf5LH7YR9yfFy1Y", "name" : "Portishead", "type" : "artist" }], "next" : "https://api.spotify.com/v1/me/following?type=artist&after=6liAMWkVf5LH7YR9yfFy1Y&limit=50", "total" :

Retrofit2.0 is returning 404 not found

巧了我就是萌 提交于 2019-12-12 10:16:45
问题 Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://ipAdress/SaveImg/DouBanGirl") .addConverterFactory(GsonConverterFactory.create()) .build(); imgApi imgService = retrofit.create(imgApi.class); Call<Img> imgCall = imgService.getImg("20151119"); imgCall.enqueue(new Callback<Img>() { @Override public void onResponse(retrofit.Response<Img> response, Retrofit retrofit) { Log.d(TAG, response.code() + " "); } @Override public void onFailure(Throwable t) { Log.d(TAG, t.getMessage()); } });

How to cancel individual network request in Retrofit with RxJava?

允我心安 提交于 2019-12-12 10:09:12
问题 I am downloading some files from the network using retrofit and rxjava. In my app, the user may cancel the download. Pseudo Code: Subscription subscription = Observable.from(urls) .concatMap(this::downloadFile) .subscribe(file -> addFileToUI(file), Throwable::printStackTrace); Now, If I unsubscribe this subscription, then all requests get canceled. I want to download one by one, that's why used concatMap. How do I cancel particular request? 回答1: There is a mechanism to cancel individual flows