retrofit

Retrofit How To Print Out Response JSON

Deadly 提交于 2019-12-21 17:50:29
问题 I'm using Retrofit and I want to get access to the JSON response that is returned from the server. Could someone please advise me. Thanks 回答1: if you only want to see the respones for debugging purpose just turn on debugging in retrofit and look at the log. It's something like: restAdapter.setDebuggingEnabled(true); If you need access to the direct response in code all of the time, you should be doing that at the httpclient level as it's basically bypassing the purpose of retrofit 回答2: To

RxJava and Retrofit - first steps with Rx

核能气质少年 提交于 2019-12-21 17:32:08
问题 With RxJava (without Retrolambda), I would like to do some API calls and complete my data with it. My incomplete object is a 'TvShow' with a list of object 'Season'. This 'Season' is empty and I need to complete it with episodes. Observable<TvShow> getDataTVShow(long idTvShow) //get TvShow with empty seasons (except season number) Observable<Season> getDataSeason(long idTvShow, int seasonNumber); //get one complete season with episodes So I want to: Get my 'TvShow' object (OK) Iterate over

NetworkOnMainThread RxJava + Retrofit + Lollipop+

我与影子孤独终老i 提交于 2019-12-21 12:17:08
问题 I'm getting reports of a NetworkOnMainThread exception on Lollipop+ when running an https api call using Retrofit and RxAndroid . I have isolated the code and created the following example that still fails. Here's the build.gradle : apply plugin: 'com.android.application' apply plugin: 'me.tatarka.retrolambda' android { compileSdkVersion 23 buildToolsVersion "23.0.1" defaultConfig { applicationId "com.example.bug" minSdkVersion 9 targetSdkVersion 23 versionCode 1 versionName "1.0" }

retrofit + okhttp : Retrieve GZIPInputStream

╄→гoц情女王★ 提交于 2019-12-21 07:27:33
问题 I have a problem when i activate gzip on WS using retrofit 1.4.1 and okhttp 1.3.0. RequestInterceptor requestInterceptor = new RequestInterceptor() { @Override public void intercept(RequestFacade request) { request.addHeader("content-type", "application/json"); request.addHeader("accept-encoding", "gzip"); // Here is the problem } }; RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(Constants.HOST) .setLogLevel(RestAdapter.LogLevel.FULL) .setRequestInterceptor

Why RxJava with Retrofit on Android doOnError() does not work but Subscriber onError does

旧城冷巷雨未停 提交于 2019-12-21 06:51:19
问题 can someone explain me why code like this: networApi.getList() .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .doOnError(throwable -> { throwable.getMessage(); }) .doOnNext(list -> { coursesView.populateRecyclerView(list); courseList = (List<Course>) courses; }).subscribe(); If there is no internet goes into doOnError but throws it further so the app goes down, but code like this: networkApi.getList() .subscribeOn(Schedulers.newThread()) .observeOn

How to parse a JSON reply when using retrofit when the reply is sometimes an object and sometimes an array?

Deadly 提交于 2019-12-21 06:09:12
问题 I am using Retrofit to get a JSON reply. Here are parts of my implementation - @GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); and the class Bills is - public static class Bills { @SerializedName("report") public ArrayList<BillItem> billItems; } The BillItem class is as follows - public static class BillItem { @SerializedName("id") Integer entryID; @SerializedName("employee_id") Integer employeeDBID; @SerializedName("type") String type;

Retrofit add header with token and id

Deadly 提交于 2019-12-21 05:12:17
问题 I have a problem with getting authenticated user. Before it I got token and user id. Now i need to get user from server using access token and id. I have header format Now I'am trying to add header with user token and id using interceptor. My code: Interceptor interceptor = new Interceptor() { @Override public okhttp3.Response intercept(Chain chain) throws IOException { Request newRequest = chain.request().newBuilder() .addHeader("Accept", "application/json") .addHeader("authorization", token

Robolectric + rxJava + retrofit Second call throws java.io.InterruptedIOException

巧了我就是萌 提交于 2019-12-21 05:04:16
问题 I am developing and android app. I am using retrofit (with OkClient) for api requests and Robolectric for testing. My api looks like this: @GET("/v1/book/{bookId}") Observable<Book> getBook(@Path("bookId") int bookId); Just for Robolectric I am forcing api calls to be synchronous. The restAdapter builder looks like this: RestAdapter.Builder builder = new RestAdapter.Builder().setEndpoint(environment.getServerEndpoint()) .setClient(new OkClient(client)) .setExecutors(new ImmediateExecutor(),

How to OAuth 2.0 with Retrofit Android

纵饮孤独 提交于 2019-12-21 05:01:04
问题 I'm using Retrofit library and I wanted to implement OAuth 2.0 on every API call in order to authenticate those calls. How can I achieve that? Can you explain me step by step? I have followed some blogs but didn't understand how to do that. 回答1: I highly recommend you to check u2020 source code. You can achieve this with a OkHttp interceptor (Retrofit 1.x or Retrofit 2.x) or a RequestInterceptor if you stay with Retrofit 1.x. 回答2: I think for the oAuth 2.0 process its better if you open

Retrofit JSON deserializing object's $ref reference to its original copy

梦想与她 提交于 2019-12-21 04:53:11
问题 I am using Microsoft.Net with Breeze for APIs and the results I get using Retrofit have nested repeated same objects. For example EmployeeJob has Customer navigation property so the APIs result looks like this { Id:1, "Customer_Id": 39, "Customer": { "$id": "2", "$type": "Wit.Trade.Entities.Customer, Wit.Trade", "CourtesyTitle": "Mr", "FirstName": "Ahmad" } } { Id:2 "Customer_Id": 39, "Customer": { "$ref": "2" //here same customer Ahmad }, } Now the Java List I get of these EmployeeJobs has