retrofit2

How to parse list of JSON objects surrounded by [] using Retrofit and GSON?

心不动则不痛 提交于 2019-11-29 01:50:21
问题 I've created a simple REST endpoint: http://<server_address>:3000/sizes This URL returns a very simple response containing a json array as follows: [ { "id": 1, "name": "Small", "active": true }, { "id": 2, "name": "Medium", "active": true }, { "id": 3, "name": "Large", "active": true } ] Now, I'm trying to consume this response using Retrofit 2 with GSON . I've added a model: @lombok.AllArgsConstructor @lombok.EqualsAndHashCode @lombok.ToString public class Size { private int id; private

Internet check, where to place when using MVP, RX and Retrofit

梦想的初衷 提交于 2019-11-28 22:25:31
问题 I have went through this and this post. So I really agree with the second post that presenter should not be aware of android specific thing. So what I am thinking is putting internet check in service layer. I am using Rx Java for making network calls, so I can either place the network check before making a service call, so this way I need to manually throw and IOException because I need to show an error page on view when network is not available, the other option is I create my own error

How to mock services with Retrofit 2.0 and the new MockRetrofit class?

孤街浪徒 提交于 2019-11-28 21:06:06
问题 Using Retrofit 1 we used to mock web services and simulate network latency as following: MockRestAdapter mockRestAdapter = MockRestAdapter.from(restAdapter); return mockRestAdapter.create(MyService.class, new MyServiceMock()); Where MyService is the service Interface (returning responses as Rx Observables), and MyServiceMock is a class that implements this interface. In Retrofit 2.0.0-beta3 there is a brand new mocking system (see: https://github.com/square/retrofit/pull/1343) that is not yet

Dagger + Retrofit. Adding auth headers at runtime

拈花ヽ惹草 提交于 2019-11-28 17:07:04
问题 I'm wondering if there is a way for Dagger to know that it should recreate an object when new data is available. The instance I am speaking of is with the request headers I have for retrofit. At some point (when the user logs in) I get a token that I need to add to the headers of retrofit to make authenticated requests. The issue is, I'm left with the same unauthenticated version of retrofit. Here's my injection code: @Provides @Singleton OkHttpClient provideOkHttpClient(Cache cache) {

How do I parse a field from a deep nested json object using Gson and retrofit in android?

拟墨画扇 提交于 2019-11-28 12:06:18
问题 I have a unique situation where I have to get certain times from a json's deeply nested object. It's a little complex, I couldn't find a solution so looking for ideas and ways to tackle this I have a the json as follows: [{ "mySpaceId": 73220, "myBuildingId": 14019, "myFloorId": 10569, "myFloorNumber": "4", "myFloorName": "4th Floor", "spaceName": "My Room 4", "capacity": 5, "type": "huddle", "busyAt": [] }, { "mySpaceId": 73219, "myBuildingId": 14019, "myFloorId": 10569, "myFloorNumber": "4"

Retrofit2 Tail Recursion Using RxJava / RxAndroid

痞子三分冷 提交于 2019-11-28 11:29:56
问题 I am really trying to get a hang of using Retrofit with RxJava / RxAndroid . I've done this using normal Retrofit2 Callback method in a previous app without the use of Reactive Programming and it worked fine. So, here is it. I need to Tail Recall a function meant to fetch all Local Government from the server. The API uses pagination (I have to construct the URL with ?page=1, perPage=2) . I've to do this till I've the whole data. So, below is my Rx code public static Observable<LgaListResponse

NPE error using Retrofit

别说谁变了你拦得住时间么 提交于 2019-11-28 11:28:08
问题 I want to login in some service called vid.me,https://api.vid.me/oauth/authorize with POST.But when I try to get data from log I have NullPointerException.I tryed to make Toast and have this error too.I'm trying to get response code to see I did this right or no. my API class: public interface VideoApi { @GET("/videos/featured") Call<Videos> getFeaturedVideo(); @GET("/videos/new") Call<Videos> getNewVideo(); @FormUrlEncoded @POST("oauth/authorize") Call<SignInResults>insertUser(@Field("name")

How to parse dynamic JSON with Retrofit?

送分小仙女□ 提交于 2019-11-28 09:43:52
问题 I have dynamic JSON, here is example: http://pastebin.com/QMWRZTrD How I can parse it with Retrofit? I failed to generate POJO classes, since I have dynamic fields like "5411" and "5412". EDIT : I solved it by using Map, since first value is always integer, and second is list of objects. @FormUrlEncoded @POST("history.php") Observable<Map<Integer, List<Vehicle>>> getHistory(@Field("uredjaji") String vehicleId, @Field("startDate") String startDATE, @Field("endDate") 回答1: you can use Map to

multiple api request using retrofit and rx java

拟墨画扇 提交于 2019-11-28 09:29:06
I am new to android and I have a scenario where I want to get get data from multiple api. Let suppose api_a , api_b , api_c , api_d . These api are independent of each other but I want to show data from these api in a mix Recycler View ( horizontal and vertical ). So I want to make these api call in such a manner so that I can get every api data at a time so that i can display in recycler view. I already using retrofit 2 but for that I had to chain them one by one which is very lengthy and I think this is not a feasible approach. I know little bit about RX JAVA ,but I only know how to make one

java.lang.IllegalArgumentException: Illegal URL with retrofit

為{幸葍}努か 提交于 2019-11-28 09:05:08
问题 i'm trying to call an api in my application i've the following url template test-test.domainname.com/feeds/json/v3/attribute/attribute i'm using retrofit 2 but i get the following fatal exception Illegal URL: test-test.domainname.com and this is my interface public interface Iinterface{ @GET("feeds/json/v3/attribute/"+attribute) Call<ArrayList<result>>getresult(); } can someone help me with this problem ... 回答1: my base URL is here: http://myapiname.azurewebservices.net and feed method is