retrofit2

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

大憨熊 提交于 2019-12-02 07:05:48
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/3377/collections/men.jpg?v=1525065071" }, "title": "Men", "sort_order": "best-selling", "published_at"

Android Upload Multiple Files In A Single Request

China☆狼群 提交于 2019-12-02 04:27:16
I'm posting content to the server in a multipart/form-data request. and the data I'm posting contains multiple parameters including a file array parameter (files[]). Using postman I'm setting the parameters and the files as: first-parameter=text content second-parameter=text content files[0]={first selected file} files[1]={second selected file} Submitting this request on postman is always successful, and the files are uploaded successfully. When I generate code snippets on postman, this is the result: POST /api/*******/new HTTP/1.1 Host: ***.***.***.*** ip-address Authorization: {authorization

How to provide Context with Dagger2

你离开我真会死。 提交于 2019-12-02 03:12:14
I am learning Android and I am following some guides for Retrofit2 with RxJava and Dagger2. Now I want to handle no internet connection case. I've found this answer , which seems to be elegant, but I do not understand how to apply it. I've got some NetworkModule , with OkHttpClient provider. I assume I need to create OkHttpClient.Builder with interceptor. So it should look something like this: ` @Provides @Singleton OkHttpClient provideOkHttpClient(Cache cache) { ConnectivityInterceptor ci = new ConnectivityInterceptor(networkObservable())); OkHttpClient.Builder.addInterceptor(ci) return

How can I update Activity/Fragment UI from Retrofit onResponse()?

折月煮酒 提交于 2019-12-02 03:03:58
I want to use Retrofit 2.1.0 for my next Android project. I would like to use Design Pattern and therefore create separate classes for every REST call i.e IBalanceService.java public Interface IBalanceService{ @GET("users/{username}") void getUser(@Path("username") String username, Callback<User> cb); } BalanceRestClient.java public class BalanceRestClient{ String username = "Makarov"; Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://hovermind.com") .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(rxAdapter) .build(); IBalanceService bs = retrofit.create

Trying to get data for POST method Retrofit

烂漫一生 提交于 2019-12-02 02:59:28
问题 Im trying to get username when I try to login to wev service.I need this username to check did I this right or no.But have NPE when try to get data,but when I just make Toast without data,it works!onResponse work,but I must to get code of this operation to build logic of my app.For example if my code==200,build new activity,else-build alertdialog or something else. What I did wrong? myFragment: public class FeedFragment extends Fragment { EditText username; EditText password; Button btnLogin;

Retrofit Offline cashing returns a null response.body()

你离开我真会死。 提交于 2019-12-02 02:58:37
I tried this link and this link to construct an offline Retrofit cache. The problem is that if I put the phone in Airplane mode, the Response.body() is always null. Here's my code: OkHttpClient client = new OkHttpClient .Builder() .cache(new Cache(App.sApp.getCacheDir(), 10 * 1024 * 1024)) // 10 MB .addInterceptor(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); if (App.isNetworkAvailable()) { request = request.newBuilder().header("Cache-Control", "public, max-age=" + 60).build(); } else { request = request.newBuilder(

Trying to get data for POST method Retrofit

♀尐吖头ヾ 提交于 2019-12-02 02:12:01
Im trying to get username when I try to login to wev service.I need this username to check did I this right or no.But have NPE when try to get data,but when I just make Toast without data,it works!onResponse work,but I must to get code of this operation to build logic of my app.For example if my code==200,build new activity,else-build alertdialog or something else. What I did wrong? myFragment: public class FeedFragment extends Fragment { EditText username; EditText password; Button btnLogin; public List<SignInResult> signInResult; public static final String ROOT_URL = "https://api.vid.me/";

Issue with Retrofit Response

ぃ、小莉子 提交于 2019-12-02 01:01:59
问题 I am trying to get List of States through Retrofit and trying to add in Searchable Spinner. What I get : I am getting List of States in Response. I can access one state in Spinner. What i want : I want to access multiple States in Spinner. Code : getMainApp().electAPI.getStates().enqueue(object : Callback<Responseval>{ override fun onFailure(call: Call<Responseval>, t: Throwable) { Toast.makeText(this@MainActivity, t?.message, Toast.LENGTH_SHORT) } override fun onResponse(call: Call

Deserializing json from retrofit using jackson where same variable name can represent two different objects

自闭症网瘾萝莉.ら 提交于 2019-12-01 23:16:11
The response from retrofit2 may be of the following types.(and we don't know before hand which response will come) { "id": "abc", "place": "LA", "driverId": "abbabaaan" } or { "id": "abc", "place": "LA", "driverId": { "name": "xyz", "id": "jygsdsah", "car": "merc" } } Is there any way to define a class so that while deserializing jackson will check the type of object "driverId" contains and assigns it to say "driverIdObj" field or "driverIdStr" field in the class. Lucian You could deserialize to a Map. Afterwards, you could inspect the map and decide to which of the 2 types you convert the map

Upload a file to AWS S3 pre-signed URL using Retrofit2

北城以北 提交于 2019-12-01 21:58:23
I'm trying to upload a file to Amazon's S3 using a pre-signed URL. I get the URL from a server which generates the URL & sends it to me as part of a JSON object. I get the URL as a String, something like this: https://com-example-mysite.s3-us-east-1.amazonaws.com/userFolder/ImageName?X-Amz-Security-Token=xxfooxx%2F%2F%2F%2F%2F%2F%2F%2F%2F%2Fxxbarxx%3D&X-Amz-Algorithm=xxAlgoxx&X-Amz-Date=20170831T090152Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Credential=xxcredxx&X-Amz-Signature=xxsignxx Unfortunately, when I pass this to Retrofit2, it modifies the String attempting to make it into a