retrofit2

Kotlin 1.2.21 + SimpleXml 2.3.0 - consume List error (must mark set get method)

浪子不回头ぞ 提交于 2019-12-01 04:11:16
I'm trying to consume XML using SimpleXML by Retrofit 2. After hours of struggling with Kotlin I decided to try Java version and the convert then to Kotlin. And Java version worked well... error: java.lang.RuntimeException: org.simpleframework.xml.core.MethodException: Annotation @org.simpleframework.xml.ElementList(data=false, empty=true, entry=, inline=true, name=entry, required=true, type=void) must mark a set or get method I need a Kotlin model class that will be able to consume that XML. Here's input: <feed> <entry> <id> someid </id> <published> somedate </published> </entry> <entry> <id>

How to pass custom enum in @Query via Retrofit?

霸气de小男生 提交于 2019-12-01 03:56:26
I have a simple enum: public enum Season { @SerializedName("0") AUTUMN, @SerializedName("1") SPRING; } Starting some version, GSON became able to parse such enums. To make sure, I did this: final String s = gson.toJson(Season.AUTUMN); It works as I expected. Output is "0" . So, I tried use it in my Retrofit services: @GET("index.php?page[api]=test") Observable<List<Month>> getMonths(@Query("season_lookup") Season season); /*...some files later...*/ service.getMonths(Season.AUTUMN); And also added logging to be really certain about its result: HttpLoggingInterceptor httpLoggingInterceptor = new

Add an array as request parameter with Retrofit 2

杀马特。学长 韩版系。学妹 提交于 2019-12-01 03:29:57
I'm looking for way to add an int array (e.g [0,1,3,5]) as parameter in a GET request with retrofit 2. Then, the generated url should be like this : http://server/service?array=[0,1,3,5] How to do this ? Just add it as a query param @GET("http://server/service") Observable<Void> getSomething(@Query("array") List<Integer> array); You can also use int[], or Integer... as a last param; I have finally founded a solution by using Arrays.toString(int []) method and by removing spaces in this result because Arrays.toString return "[0, 1, 3, 5]". And my request method looks like this @GET("http:/

Execute http request in parallel with Retrofit 2

元气小坏坏 提交于 2019-12-01 03:12:39
I want to implement multiple parallel request in Retrofit 2. I have the following structure to make 3 request : HistoricalRApi.IStockChart service=HistoricalRApi.getMyApiService(); //^BVSP,^DJI,^IXIC Call<HistoricalDataResponseTimestamp> call1= service.get1DHistoricalDataByStock("^IXIC"); Call<HistoricalDataResponseTimestamp> call2= service.get1DHistoricalDataByStock("^DJI"); Call<HistoricalDataResponseTimestamp> call3= service.get1DHistoricalDataByStock("^GSPC"); call1.enqueue(retrofitCallbackAmerica()); call2.enqueue(retrofitCallbackAmerica()); call3.enqueue(retrofitCallbackAmerica()); } I

Fetching json object and array from retrofit

血红的双手。 提交于 2019-12-01 02:32:49
问题 I want to fetch json from [this link][1]: https://api.myjson.com/bins/38ln5 using retrofit sample json is { "students": [ { "id": "1", "name": "Larzobispa" }, { "id": "2", "name": "La Cibeles" } ] } Please explain details how to do that. Thanks a lot, guys! 回答1: Retrofit will automatically parse JSON Object as well JSON Array. @GET("/register?email=example@123.com") public void responseString(Callback<Student> response); your model class looks like: public class Student{ private ArrayList

Retrofit,onResponse method doesnt work

我的梦境 提交于 2019-12-01 01:51:11
Im new in Retrofit,try to get data from one web server,create Model,Interface but this still not working.Problem(maybe) in method onResponse() I add to that method Log.d and Toast but I dont see Log and Toast when launch my app.Why that dont work? I can understand when I get wrong response or something else,but onResponse() dont work in general,how I think.Maybe Toast cant work withoud data,but Log.d must work without it,and Log.d havent data,just code of response. I added all depencies and tryind do this like in all tutorial,what wrong I did and what I can do to fix that? And also I try tu

Is it possible to send a String[] through Multipart using Retrofit?

老子叫甜甜 提交于 2019-12-01 01:50:40
问题 I'm developing an application where at a point the user has to choose any number of countries from a list and I must send the selected names through a multipart. I am not uploading any file along with the String[], but there is no route to upload information without it being a multipart and I don't have any saying in how the web server operates. I've attempted to simply send it as an Array, ArrayList and JsonArray as such: @Headers({ "Connection: Keep-Alive", }) @Multipart @PUT("/user/{id}")

How to handle network errors in Retrofit 2 with RxJava

泪湿孤枕 提交于 2019-12-01 01:01:30
I am using Retrofit2 with RxJava. So my call looks something like subscriptions.add(authenticateUser(mReq, refreshRequest) .observeOn(Schedulers.io()) .subscribeOn(Schedulers.io()) .subscribe(authResponseModel -> { processResponse(authResponseModel, userName, encryptedPass); }, throwable -> { LOGW(TAG, throwable.getMessage()); })); It's an authentication api. So when the api call fails, I get a response from the server like {"messages":["Invalid username or password "]} along with 400 Bad Request I get 400 Bad Request in the throwable object as expected. But I want to receive the message

Meaning of“A type-safe HTTP client for Android and Java” in Retrofit 2.0

无人久伴 提交于 2019-12-01 00:59:10
问题 Can someone please explain meaning of Retrofit's tagline : A type-safe HTTP client for Android and Java 回答1: Type safety is the extent to which a programming language discourages or prevents type errors. A type error is erroneous or undesirable program behaviour caused by a discrepancy between differing data types for the program's constants, variables, and methods (functions), e.g., treating an integer (int) as a floating-point number (float). This is common in statically typed languages

How to pass custom enum in @Query via Retrofit?

为君一笑 提交于 2019-11-30 23:54:54
问题 I have a simple enum: public enum Season { @SerializedName("0") AUTUMN, @SerializedName("1") SPRING; } Starting some version, GSON became able to parse such enums. To make sure, I did this: final String s = gson.toJson(Season.AUTUMN); It works as I expected. Output is "0" . So, I tried use it in my Retrofit services: @GET("index.php?page[api]=test") Observable<List<Month>> getMonths(@Query("season_lookup") Season season); /*...some files later...*/ service.getMonths(Season.AUTUMN); And also