retrofit2

Android Retrofit GET @Query ArrayList

青春壹個敷衍的年華 提交于 2019-12-24 04:51:04
问题 I am trying to consume a GET API that expects in its query params list an array of strings. I am using Retrofit for the task. In the API interface, I have the following defined: @GET("user/explore") Observable<User> fetchUsers(@Query("who") String who, @Query("category") ArrayList<String> categories); I am using Timber for logging and in the console, I see the request is made like the following: http://192.168.2.208:3000/api/v1/user/explore?who=SOME_USER&category=SOME_CATEGORY The expected

Parsing Retrofit2 result using Gson with different JSON structures

混江龙づ霸主 提交于 2019-12-24 04:26:17
问题 When I call the API, depending on the parameters, the name of the same field in the JSON returned changes. In the example below, in one case the field "user" is named "userA" or "userB". I'm using Gson but I don't want to create an object to parse the root of the JSON as I'm only interested in the list of users and I want my call to return this list only. { "apiVersion":"42" "usersA":[{ "name":"Foo", "lastname":"Bar" ... } ] "otherData":"..." } or { "apiVersion":"42" "usersB":[{ "name":"Foo",

How can I get the URL and method of RetroFit request on onSubscribe of RxJava 2 custom operator?

自作多情 提交于 2019-12-24 03:27:44
问题 So I'm trying to integrate Firebase performance for Http requests and add them manually as they show here (step 9). I'm using Retrofit 2 and RxJava 2, so I had the idea of doing a custom operator, check code below: Retrofit 2 Client @GET("branch-{environment}/v2/branches") fun getBranch(@Path("environment") environment: String, @Query("location") location: String, @Query("fulfilment_type") fulfilmentType: String): Single<Response<GetBranchResponse>> RxJava Call to the Retrofit Client private

Using multiple values for the same param in a multipart's PartMap request with Retrofit 2

依然范特西╮ 提交于 2019-12-24 02:25:34
问题 I want to send multiple values of the same param in a multipart query. Here is my code: Interface: @Multipart @POST("user") Observable<Void> updateUser(@PartMap() Map<String, RequestBody> partMap, @Part MultipartBody.Part photo); This request allow me to update a user with a new picture and some parameters. In the parameters I can specify the user's skills with a parameter named "skills[]". To specify the parameters that can vary in number I use a HashMap; however with a HashMap I cannot

Retrofit method return wildcard

喜欢而已 提交于 2019-12-24 01:39:53
问题 I have an API response which is meant to generically return data for various activities of our application. In an effort to make the application as generic and flexible as possible we have setup an API to deliver a collection of URLs to utilize to create various rows on our activities. Our base object looks like: public class BaseApiObject { @SerializedName("apiVersion") private String apiVersion = null; @SerializedName("totalResults") private Integer totalResults = null; } Our response for

JSON with Dynamic Keys while using Retrofit in Android

半城伤御伤魂 提交于 2019-12-24 00:37:30
问题 I'm new in using Retrofit with Android. I'm stuck at a point where I make a request to the REST Api and the response has a dynamic keys. Can anyone tell me what is the best way to parse the JSON something like this. { "Meta Data": { "1. Information": "Intraday (1min) prices and volumes", "2. Symbol": "MSFT", "3. Last Refreshed": "2017-12-01 16:00:00", "4. Interval": "1min", "5. Output Size": "Compact", "6. Time Zone": "US/Eastern" }, "Time Series (1min)": { "2017-12-01 16:00:00": { "1. open":

Android Local Tests vs Instrumented Test

佐手、 提交于 2019-12-23 20:06:16
问题 I'm trying to check if my API is available within a unit test, to be sure that it responds with 200. Now, my problem is that I'm not really sure when to use Local Test and when I have to use Android Instrumentation Tests . I know that I have to use Instrumented Tests for UI testing but how to test the endpoint? I use Retrofit2 for communication. And tried to test Endpoint in 2 ways with Local Tests. Example 1 (synchronous, does not work) public class EndpointTest { EndpointApi api;

FileNotFoundException while uploading image using Retrofit

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 17:56:36
问题 I tried to upload an image using Retrofit but I am getting this error: Unable to submit post to API: java.io.FileNotFoundException: /document/image:30231: open failed: ENOENT (No such file or directory) My interface is like this: public interface MyService{ @Multipart @POST("/url") Call<ResponseBody> addNewEvent( @Part("case_Id") int caseId,@Part MultipartBody.Part(file); } On Button click, selectImage() function is called: private void selectImage() { Intent intent = new Intent(); intent

Android Retrofit - POST request doesn't work, but in Postman it works

天大地大妈咪最大 提交于 2019-12-23 16:40:32
问题 This is the error I'm getting: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ JSON response I'm getting from Postman: { "title": "test title", "body": "test body", "userId": 1, "id": 101 } This is how I echoed the response from the rest API (used slim2 framework): $app->post('/posts', function() use($app){ $res = array( "title" => $app->request->post('title'), "body" => $app->request->post('body'), "userId"

GSON Expected BEGIN_ARRAY but was STRING at line 1 error

我怕爱的太早我们不能终老 提交于 2019-12-23 16:16:04
问题 I am trying to parse a String array using Retrofit and GSON which is returned from the API: This is what the response normally looks like (CASE 1): ["Scan finished, scan information embedded in this object", "https://www.virustotal.com/url/297c349554bdc7e2f09a85be309f08cb2f16a9174068bd5bc6e298ed90a5eed9/analysis/1485313628/", 8, 64] This is what the response looks like in a specific case (CASE 2): ["Scan request successfully queued, come back later for the report", "https://www.virustotal.com