retrofit2
Dagger + Retrofit. Adding auth headers at runtime
I personally created an okhttp3.Interceptor that does that for me, which I update once I have the required token. It looks something like: @Singleton public class MyServiceInterceptor implements Interceptor { private String sessionToken; @Inject public MyServiceInterceptor() { } public void setSessionToken(String sessionToken) { this.sessionToken = sessionToken; } @Override public Response intercept(Chain chain) throws IOException { … Read more
Retrofit2.0 gets MalformedJsonException while the json seems correct?
Finally I solved my problem which is not related to the json lenient mode, something wrong with my POST response (there some other non json output before the json data). Here is the response from JakeWharton regarding how to set Gson lenient mode: make sure that you haveļ¼compile ‘com.google.code.gson:gson:2.6.1’ Gson gson = new GsonBuilder() .setLenient() … Read more
Add cookies to retrofit 2 request
First of all: cookie is not the same as a header. Cookie is a special HTTP header named Cookie followed by list of the pairs of keys and values (separated by “;”). Something like: Cookie: sessionid=sessionid; token=token Since you cannot set multiple Cookie headers in the same request you are not able to use two … Read more
How use Kotlin enum with Retrofit?
enum class VehicleEnumEntity(val value: String) { @SerializedName(“vehicle”) CAR(“vehicle”), @SerializedName(“motorcycle”) MOTORCYCLE(“motorcycle”), @SerializedName(“van”) VAN(“van”), @SerializedName(“motorhome”) MOTORHOME(“motorhome”), @SerializedName(“other”) OTHER(“other”) } Source
Retrofit optional and required fields
@FieldMap and @Query params both support optional fields. As you mentioned, simply pass null if you don’t want to pass a value.
IllegalArgumentException: Could not locate call adapter for rx.Observable RxJava, Retrofit2
Be sure to add implementation ‘com.squareup.retrofit2:adapter-rxjava2:2.4.0’ or whatever version you are using to your dependencies, and then configure retrofit with that converter: Retrofit retrofit = new Retrofit.Builder() .baseUrl(endpoint) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); Updated RxJavaCallAdapterFactory was renamed to RxJava2CallAdapterFactory. Changed the snipped above.