retrofit2

Implement Room with RxJava and Retrofit

白昼怎懂夜的黑 提交于 2019-12-11 06:19:21
问题 I am trying to use Room with RxJava and Retrofit, Before You recommend use a component arch (In this opportunity is not possible, the project is in and 50% and Just need to continue with the arch clean). So the problem is this. I have a web service that returns a POJO . Something like this: { "success":"true", "message":"message", "data":{[ "id":"id", "name":"name", "lname":"lname", ]} } POJO is more complex but for the example is ok with this. I need to do that since my view make query to

Java - Convert xml to JAVA Pojo classes including java annotations(Simplexml)

拜拜、爱过 提交于 2019-12-11 06:11:30
问题 I am developing an application which uses XML as API request and response body. To fetch and parse this using retrofit, i have used SimpleXml as the converter for retrofit. But in order to create pojo classes for the corresponding XML, i could not find any online methods similar to jsonchema2pojo. And since the XML involved in the project is huge in size, it is very time consuming to create POJO classes manually. I am posting this question as an FAQ, since i had some trouble finding an easy

java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY Kotlin

跟風遠走 提交于 2019-12-11 06:06:47
问题 I am trying to implement login on my app using Retrofit, i however keep getting this error not sure whats wrong, java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY This is the response from postman { "isSuccessful": true, "message": "successful", "user": [ { "id": 1, "name": "Raymond Gitonga", "email": "xyz@gmail.com", "phone": "07222XXXXX" } ] } I have two model classes the User model class data class User( val id:Int, val name: String, val email:String, val phone

android retrofit send array as x-www-form-urlencoded

核能气质少年 提交于 2019-12-11 05:56:49
问题 I'm using retrofit as my network library, and I want to send a JSON array as x-www-form-urlencoded , but I don't know how to do that. Here is my request API : @POST("book") @FormUrlEncoded Call<BookTicket> BookFlight(@Header("Authorization") String authorization, @Header("Content-Type") String content_type, @Field("rootType") Integer rootType , @Field("BookingStep2") ArrayList<JSONObject> BookingStep2 ); Here is a sample request : { "rootType": 1, "BookingStep2": { "OriginFlightSegment": {

Android + Retrofit 2 + GSON = Unable to invoke no-args constructor for interface

淺唱寂寞╮ 提交于 2019-12-11 05:37:00
问题 I'm trying to use retrofit 2 in my app and i'm getting the folloing error: java.lang.RuntimeException: Unable to invoke no-args constructor for interface box.gov.br.ourapp.API.ClientePFApi. Register an InstanceCreator with Gson for this type may fix this problem. And... I dunno where's the problem =/ My java class: public class ClientePFVisao360 { private static final long serialVersionUID = 3182722297876508581L; @SerializedName("txCPF") @Expose public String txCPF; @SerializedName("nuCocli")

Android implementing HostSelectionInterceptor for dynamic change url using Dagger 2

穿精又带淫゛_ 提交于 2019-12-11 05:26:05
问题 i just learn about how can i implementing Retrofit with Dagger2 to set dynamic change url on this reference i try to make simple module with HostSelectionInterceptor class to use that on Dagger2, but i can't make that correctly and i get error: my NetworkModule : @Module(includes = ContextModule.class) public class NetworkModule { @Provides @AlachiqApplicationScope public HttpLoggingInterceptor loggingInterceptor() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(new

Get Data from API using retrofit

与世无争的帅哥 提交于 2019-12-11 05:24:33
问题 I need to get the details from the API and display them in textviews. Here's my API in JSON format : https://imgur.com/a/WI98ymx I need to get the data like username, user image, user phone number etc in Strings and display them in textviews. How do i request all the fields and show the list in different textviews? Here's my Login interface package com.example.hb.loginapi; import java.util.List; import retrofit2.Call; import retrofit2.http.GET; import retrofit2.http.POST; import retrofit2

Call API on server that is signed using Self-Signed Certificate

时光怂恿深爱的人放手 提交于 2019-12-11 05:07:03
问题 I'm working on an Android application that call some API s over https . using retrofit2 and okhttp3 . During my development I use a self-signed certificate that I generate in server. I face a lot of problems in calling API s as I'm using a self-signed certificate, I solve them all but stuck on this exception SSLPeerUnverifiedException . Currently I had copy my certificate ServerCertificate.cer to Download directory in order to load it and add it to allowed KeyStore . I try a lot of solutions

Retrofit. Get response if (!response.isSucessful())

安稳与你 提交于 2019-12-11 04:46:31
问题 In new retrofit I'm making call and overriding 2 methors onResponse and onFailure. If retrofit sucesfully parsed response to my Class Model I can get it simple but how can I get server response if (!response.isSucessful()) ? I see code error. Raw response. Error body. But didn't see response from server. This is my error from server... how to get it from response? { "message": "422 Unprocessable Entity", "errors": { "lang": [ "Lang required." ], "provider": [ "Provider required." ] }, "status

Android test method called after presenter executes retrofit call

大憨熊 提交于 2019-12-11 04:39:19
问题 I'm using Mockito to test my views but my tests are failing because of a method that is supposed to be called after a retrofit call is complete. How can I mock a view who's method is called by presenter after completion of a retrofit call? I'd like to verify that unBlockUI() below has been called. My tests show blockUI() is called but unblockUI() is not being called. I get a fail message Wanted but not invoked: view.unBlockUI(); In my presenter I have the method public void fetchResults(){