retrofit2

Gson deserialize interface to its Class implementation

[亡魂溺海] 提交于 2019-12-09 09:44:49
问题 I am using Retrofit 2.1.0 with converter-gson:2.1.0 and separately gson:2.6.2 in order to customize the serialization/deserialization. The problem is that my POJOs should be hidden behind interfaces and I want to tell Gson which class should be the deserialized interface. And after the deserialization/ serialization Retrofit should be able to return the interface. It would be good if I can take advantage of Generics and easily create a way to tell Gson or Retrofit to serialize/deserialize

Unexpected end of stream on okhttp3

妖精的绣舞 提交于 2019-12-09 05:59:40
问题 I had followed this link to refresh access token. While adding Authenticator to okHttp getting error of Unexpected end of stream on okhttp3 from retrofit call back onFailure method public class TokenAuthenticator implements Authenticator { AccessTokenRefreshModel accessTokenRefreshModel = null; @Override public Request authenticate(Route route, Response response) throws IOException { Call<UserLogin> call = iService.refreshAccessToken(BuildConfig.CLIENT_ID, refreshToken); UserLogin userLogin =

How to disable a body data getting encoded in soap, retrofit request

北慕城南 提交于 2019-12-09 03:23:09
问题 I have a request data where one of the element takes xml as value. While sending the data to the server using @Body my inner xml is getting encoded(html encoded). Because of this service is failing in server side. How to disable the inner xml getting encoded . sample: <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/soap/envelope/"> <soap12:Body> <UpdateASN xmlns="http://tempuri.org/">

Access raw response body in Retrofit callback

余生颓废 提交于 2019-12-08 16:55:17
问题 Retrofit version: 2.1.0 OkHttp version: 3.4.1 In the onResponse method of my Retrofit Callback implementation, I have the following logic: @Override public void onResponse(Call<BaseResponseBody<T>> call, Response<BaseResponseBody<T>> response) { if (response != null && response.isSuccessful() && response.body() != null && response.body().containsValidSuccess()) { // Perform actions using response.body().getValue(). } else { // If containsValidSuccess returns false, show a dialog that includes

How to handle multiple possible response types with Retrofit2, Gson and Rx

試著忘記壹切 提交于 2019-12-08 16:40:52
问题 The API i have to use sucks, and always returns HTTP 200. But sometimes there is proper response: [{"blah": "blah"}, {"blah": "blah"}] and sometimes, there is error: {"error": "Something went wrong", "code": 123} I'm using Retrofit2 with Gson converter and Rx adapter: final Api api = new Retrofit.Builder() .baseUrl(URL) .client(client) .addCallAdapterFactory(RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io())) .addConverterFactory(GsonConverterFactory.create()) .build() .create(Api

Retrofit 2 prints empty response body in log with HttpLoggingInterceptor.Level.BODY

人走茶凉 提交于 2019-12-08 16:09:38
问题 I use Retrofit 2.0.0 . This is the code that builds my HTTP client protected OkHttpClient getHttpClient(){ OkHttpClient.Builder builder = new OkHttpClient.Builder(); builder.addInterceptor( chain -> { Request original = chain.request(); Request.Builder requestBuilder = original.newBuilder(); requestBuilder.header("Accept-Language", App.getInstance().getPrefs().getSelectedLanguage().toLowerCase()); requestBuilder.header("Accept-Encoding", "gzip"); if(API.this instanceof PrivateAPI){

UndeliverableException while calling onError of ObservableEmitter in RXjava2

試著忘記壹切 提交于 2019-12-08 15:58:21
问题 I have a method which creates an emitter like below, there are a problem(maybe it is normal behavior) with calling onError in retrofit callback. I got UndeliverableException when try to call onError. I can solve this by checking subscriber.isDiposed() by I wonder how can call onError coz i need to notify my UI level. Addition 1 --> RxJava2CallAdapterFactoryalready implemented private static Retrofit.Builder builderSwift = new Retrofit.Builder() .baseUrl(URL_SWIFT) .addCallAdapterFactory

Retrofit2: How to properly check the validity of response.body()?

别等时光非礼了梦想. 提交于 2019-12-08 15:41:02
问题 Since version retrofit2.retrofit:2.3.0 I'm getting NullPointerException warnings on response.body() even when checking the body for null before: Method invocation 'getCar()' may produce 'java.lang.NullPointerException' In the changelog for 2.3.0 was an entry related to null checks: Retrofit now uses @Nullable to annotate all possibly-null values. [...] We use @ParametersAreNonnullByDefault and all parameters and return types are never null unless explicitly annotated @Nullable. It that the

Retrofit 2 Error:java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 6 column 1 path

ぃ、小莉子 提交于 2019-12-08 13:55:54
问题 Help Me for this issue, please code is as follow Activity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TaskData taskData= new TaskData(); taskData.setEmail("praik@gmail.com"); Task task= new Task(); task.setTaskData(taskData); Log.v("@@@WWE"," Call Initiated"); task.setTask("getUserDetail"); JSONObject taskDatas= new JSONObject(); JSONObject taskM= new JSONObject(); try { taskDatas.put("email","praik@gmail.com

Using Retrofit 2 but, have Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

北慕城南 提交于 2019-12-08 13:18:49
问题 I make request get photos from Flickr, using Retrofit 2. I create a class for parsing it: public class FlickrResult { @SerializedName("photos") @Expose private FlickrPhotos photos; @SerializedName("stat") @Expose private String stat; public FlickrPhotos getPhotos() { return photos; } public class FlickrPhotos { @SerializedName("page") @Expose private int page; @SerializedName("pages") @Expose private String pages; @SerializedName("perpage") @Expose private int perpage; @SerializedName("total"