retrofit2

Retrofit error: JSON document not fully consumed

拜拜、爱过 提交于 2019-12-11 19:48:39
问题 Please I'm stock using retrofit for few days, I'm trying to parse the response to my POJO class, initially the error was setlenient to true wich i did and ended up here, no related questions here seem to solving my problem JSON Response from server { "error": false, "message": "Login successful", "student": { "fullname": "Idris Muhammad", "matric": "u14/fns/csc/066", "department": "computer science", "gender": "male", "email": "mail4idris@gmail.com", "phone": "08065468035", "level": 100,

converting json string with Gson for generic model

本秂侑毒 提交于 2019-12-11 19:26:20
问题 i have class like this public class Response<T>{ T item; List<T>; } so how can to deserializeding String in this pattern to one generic class with gson.fromJson(targetString,...) ? i glad to used in retrofit library where Response is returned parameter in desired interface 回答1: convert list to gson public <T> String setList(List<T> list) { Gson gson = new Gson(); return gson.toJson(list); } convert gson to list public List<(desired class)> getList(){ Gson gson = new Gson(); String json =

KotlinNullPointerException in UnitTest

流过昼夜 提交于 2019-12-11 18:42:46
问题 I have following ViewModel class : class MovieViewModel @JvmOverloads constructor( dataSource: MoviesRemoteDataSource, sortType: SortType? = null) : ViewModel() { // thread pool used for network requests @Suppress("PrivatePropertyName") private val NETWORK_IO = Executors.newFixedThreadPool(5) private val query = MutableLiveData<String>() private val repoResult = map(query) { PageKeyRepository( dataSource = dataSource, sortType = sortType, networkExecutor = NETWORK_IO).getMovies(it, 20) } val

okhttp Interceptors to intercept when internet is disabled

孤街浪徒 提交于 2019-12-11 18:09:38
问题 I am working on network module where it should provide offline data where I am fetching previously stored JSON response from local db and building response and returning to the application. All this is happening in my okhttp Interceptor at application level. I know I could have checked for n/w availability with ConnectivityManager Every time I tried with n/w disabled or changing server false server URL for testing, Debugger just disappears call to chain.proceed(request) Please note I knew I

How to dynamically pass different urls in retrofit2 android using Dagger

守給你的承諾、 提交于 2019-12-11 17:53:36
问题 In the ApplicationClass I'm passing one url and i use it in ActLogin.java Now I want to pass ActUpcomingEvents another url different than ActLogin.java How to achieve this NetModule.java @Module public class NetModule { String mBaseUrl; Application mApplication; // Constructor needs one parameter to instantiate. public NetModule(String baseUrl, Application application) { this.mBaseUrl = baseUrl; this.mApplication = application; } // Dagger will only look for methods annotated with @Provides

RxJava 2: flatMapCompletable is not waiting for the Completable to finish

穿精又带淫゛_ 提交于 2019-12-11 17:51:55
问题 The use case: There is a dataset of a POJO class. In this case it is an ArrayList . I have created a class which extends ArrayList with some helper methods which divides the list into pages. A page just divides the list into small pages for uploading to a REST API. I have created an Iterable from an Iterator , which checks whether a page is available for uploading and then fetches that page. The page needs to uploaded and on a success event of the upload, it will be removed and then again the

Error on retrieving JSON field in Retrofit 2.0 [duplicate]

半城伤御伤魂 提交于 2019-12-11 17:47:53
问题 This question already has answers here : Gson, how to deserialize array or empty string (6 answers) Closed last year . I have a problem. I'm using Retrofit 2.0 to make calls to my api from my Android app. All works fine, but when I'm receive a empty field I get this error: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 8599 path $.meta.pagination.links The problem is with links field, that sometimes is not empty "links": { "next": "http://www.example.com, } But when it's empty the

How to pass Retrofit response to RecyclerViewAdapter in Android Google Books API

前提是你 提交于 2019-12-11 17:34:03
问题 I've been using Retrofit2.0 (just learned how to use it) to retrieve Google Books API info, I have finally succeeded. But now I don't know know how to pass it to RecyclerView since now my models have gotten revised and now deal with nested models (I think that is the correct term) compared to what I had before to (old Stack Overflow question here). Currently, I'm getting this error: E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.android_myneighborsbookshelf, PID: 8806 java.lang

Retrofit client and response with Transfer-Encoding: chunked

霸气de小男生 提交于 2019-12-11 17:08:28
问题 I'm working on a Android sample app that get film list from http://www.omdbapi.com/. The REST service is: http://www.omdbapi.com/?s=star&apikey=d497e644 I'm using Retrofit to write the client. public interface OmdbApi { @Streaming @GET("./") @Headers({"Cache-control: no-cache"}) Call<Search> search(@Query("s") String search, @Query("apikey") String apiKey); @Streaming @GET("./") @Headers({"Cache-control: no-cache"}) Call<FilmDetail> getFilm(@Query("i") String uid, @Query("apikey") String

Issues with GET request using Retrofit in android studio

我只是一个虾纸丫 提交于 2019-12-11 17:05:23
问题 I'm using Retrofit 2 in Android Studio to get stop information in JSON form from the CUMTD api for stops by search and for some reason the connection keeps on failing, are the query parameters and everything else correct, i used to the JSON to pojo converter for the model class so it should be correct or is it something from main activity? Heres the URL I'm trying to connect to https://developer.cumtd.com/api/v2.2/json/GetStopsBySearch?key=b7cd7d8c64b24b4f8415aeb57d6f7f74&query=transit