retrofit2

How to fix Expected BEGIN_OBJECT in Retrofit?

99封情书 提交于 2019-12-02 14:03:12
问题 In my application i want use Retrofit for get some data from server. I write below codes but when run application and call api show me below error : E/socketLogResponse: Err : com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ Please see my above codes and help me API response from server : { "status": "ok", "time": 0.014972925186157227 } ApiService interface : @POST("api/log") Call<SocketPingResponse>

Error: onFailure:com.google.gson.JsonSyntaxException: java.lang.NumberFormatException: Expected an int but was 57213780054

让人想犯罪 __ 提交于 2019-12-02 12:19:41
问题 Cannot get the Response from the Retrofit showing the JsonSyntaxException. I am getting the perfect response in Logcat by HTTPLoggingInterceptor but unable to get the resonse on onSuccess() method in call.enque(). Here is my api. { "collection_listings": [ { "collection_id": 57213780054, "updated_at": "2018-04-30T02:12:55-04:00", "body_html": "", "default_product_image": null, "handle": "men", "image": { "created_at": "2018-04-30T01:11:11-04:00", "src": "https://cdn.shopify.com/s/files/1/2331

Call another Retrofit call on Subject emission

ε祈祈猫儿з 提交于 2019-12-02 11:12:21
I have a following class: public class SessionStore { Subject<Session, Session> subject; public SessionStore() { subject = new SerializedSubject<>(BehaviorSubject.create(new Session()); } public void set(Session session) { subject.onNext(session); } public Observable<UserSession> observe() { return subject.distinctUntilChanged(); } } In activity I observe the session and perform network operation on each change: private Subscription init() { return sessionStore .observe() .flatMap(new Func1<Session, Observable<Object>>() { @Override public Observable<Object> call(Session session) { return

OkHttp 3 response cache (java.net.UnknownHostException)

可紊 提交于 2019-12-02 10:44:57
I'm really stuck at this problem. I want to cache server response for some time to use the data when device is offline. So I set a cache to my OkHttpClient . Also I set Cache-Contlol header. Here is my code: public class MainActivity extends AppCompatActivity { Retrofit retrofit; RecyclerView recyclerView; RandomUserAdapter mAdapter; Cache cache; Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initViews(); GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.create(); cache

How to download PDF file with Retrofit and Kotlin coroutines?

可紊 提交于 2019-12-02 08:30:02
I saw topics like How to download file in Android using Retrofit library? , they use @Streaming and RxJava / callbacks. I have Kotlin, coroutines, Retrofit 2.6.0 and queries like in https://stackoverflow.com/a/56473934/2914140 : @FormUrlEncoded @Streaming @POST("export-pdf/") suspend fun exportPdf( @Field("token") token: String ): ExportResponse I have a Retrofit client: retrofit = Retrofit.Builder() .baseUrl(SERVER_URL) .client(okHttpClient) .build() service = retrofit.create(Api::class.java) If a token parameter is right, the query returns PDF file: %PDF-1.4 %���� ... If it is wrong, it will

image upload using multipart retrofit 2

一个人想着一个人 提交于 2019-12-02 07:48:08
问题 Actually, I'm new in this field.facing some problem during image upload.the process automatically suspended after some time.I am attaching my code below.Please anyone helps me to solve this problem. ServerResponse.java public class ServerResponse { // variable name should be same as in the JSON response from PHP @SerializedName("success") boolean success; @SerializedName("success_msg") //@SerializedName("message") String message; String getMessage() {return message; } boolean getSuccess() {

accessing localhost laravel app routes to android studio failed

孤者浪人 提交于 2019-12-02 07:24:20
I'm developing an android app in android Studio3 that its back is laravel. For the local server, I created a virtual server by artizan. Now the problem is connecting local server (127.0.0.1:8000) to android and for this, I tried too many baseUrl in bellow Interface like: 10.0.2.2:8008, 10.0.3.2:8000, IP4, ............., :/ Interface: interface ApiInterface { @GET("stocks.json") fun getStocks(): Call<StockResponse> companion object { val BASE_URL = "http://192.168.1.106:8000/api/" fun getClient(): ApiInterface{ val retrofit = Retrofit.Builder() .baseUrl(BASE_URL) .addConverterFactory

Android - how to get another value of selected item on spinner

点点圈 提交于 2019-12-02 07:18:56
问题 I've a rest response as below, and i need to populate the output to spinner. I've been successfully pass the "name" to spinner and it's works. But I also need get the "id" so I can use the "id" for query to the another rest request. for example, I get the Province id, and then I use the Province id to get the City list. { "code": 1000, "message": "OK", "data": [ { "id": "3579010", "name": "Batu" }, { "id": "3579020", "name": "Junrejo" }, { "id": "3579030", "name": "Bumiaji" } ] } Below is the

How to fix Expected BEGIN_OBJECT in Retrofit?

让人想犯罪 __ 提交于 2019-12-02 07:16:12
In my application i want use Retrofit for get some data from server. I write below codes but when run application and call api show me below error : E/socketLogResponse: Err : com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ Please see my above codes and help me API response from server : { "status": "ok", "time": 0.014972925186157227 } ApiService interface : @POST("api/log") Call<SocketPingResponse> getSocketPingLog(@Header("jwt") String jwt, @Body SocketPingBodySendData socketPingBodySendData);

Android - how to get another value of selected item on spinner

試著忘記壹切 提交于 2019-12-02 07:06:46
I've a rest response as below, and i need to populate the output to spinner. I've been successfully pass the "name" to spinner and it's works. But I also need get the "id" so I can use the "id" for query to the another rest request. for example, I get the Province id, and then I use the Province id to get the City list. { "code": 1000, "message": "OK", "data": [ { "id": "3579010", "name": "Batu" }, { "id": "3579020", "name": "Junrejo" }, { "id": "3579030", "name": "Bumiaji" } ] } Below is the android code public void initProvinceSpinner() { Call<GetProvinceResponse> call = apiService