retrofit2

API declarations must be interfaces- Retrofit

[亡魂溺海] 提交于 2020-07-20 11:57:34
问题 I am try to do simple get response using Retrofit . And i have error java.lang.IllegalArgumentException: API declarations must be interfaces. . I can not figure out what exactly the problem. I have this error when i try to do CategoryJsonParser categoryParsed = retrofit.create(CategoryJsonParser.class); . So its my interface: public interface InterfaceForCategory { @GET("categories?api_key=l6pdqjuf7hdf97h1yvzadfce") Call<List<CategoryJsonParser>> getData(); } How i create retrofit in main act

Retrofit trailing slash on relative urls

a 夏天 提交于 2020-07-19 06:14:38
问题 Does Retrofit remove the trailing slash from a relative url for an endpoint? I have tried adding the trailing slash on one of my endpoints but when i step through with a debugger and i look at the Call object, if I drill into the delete.relativeUrl it does not show the trailing slash. 回答1: You need to manually add the slash at the end of the base URL endpoint. Let's say you have this two instances of retrofit: No Slash Retrofit retrofitNoSlash = new Retrofit.Builder() .baseUrl("https:/

Retrofit trailing slash on relative urls

☆樱花仙子☆ 提交于 2020-07-19 06:13:22
问题 Does Retrofit remove the trailing slash from a relative url for an endpoint? I have tried adding the trailing slash on one of my endpoints but when i step through with a debugger and i look at the Call object, if I drill into the delete.relativeUrl it does not show the trailing slash. 回答1: You need to manually add the slash at the end of the base URL endpoint. Let's say you have this two instances of retrofit: No Slash Retrofit retrofitNoSlash = new Retrofit.Builder() .baseUrl("https:/

Why does PDF is not able to upload in PHP API for Android Pie, Q and R using Retrofit 2 in Android/Java? [Added Bounty]

此生再无相见时 提交于 2020-07-11 07:15:06
问题 The bounty expires in 6 days . Answers to this question are eligible for a +50 reputation bounty. Priyanka Singh is looking for an up-to-date answer to this question: I need the solution that should work on all version from API 21 to 30 Update: I started Bounty for this question, because accepted solution is working till Oreo version, but my project supports from API level 21 to 30 . Please check end of the question, to see latest updates. I tried to upload a PDF file [ Not Image ] in PHP API

Why does PDF is not able to upload in PHP API for Android Pie, Q and R using Retrofit 2 in Android/Java? [Added Bounty]

£可爱£侵袭症+ 提交于 2020-07-11 07:12:29
问题 The bounty expires in 6 days . Answers to this question are eligible for a +50 reputation bounty. Priyanka Singh is looking for an up-to-date answer to this question: I need the solution that should work on all version from API 21 to 30 Update: I started Bounty for this question, because accepted solution is working till Oreo version, but my project supports from API level 21 to 30 . Please check end of the question, to see latest updates. I tried to upload a PDF file [ Not Image ] in PHP API

Retrofit POST Request with body parameters android

佐手、 提交于 2020-07-10 07:51:35
问题 I need to execute post request with retrofit but i have a problem which i can't understand very well. Before trying with code i tested api call with Postman and request look like this: Here is my android code: public class API { private static <T> T builder(Class<T> endpoint) { return new Retrofit.Builder() .baseUrl(Utils.API_BASE_URL) .addConverterFactory(ScalarsConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .build() .create(endpoint); } public static

java.io.EOFException: End of input at line 1 column 1 path $ in Android retrofit

随声附和 提交于 2020-07-06 19:33:25
问题 I'm using Retrofit to consume a REST API endpoint, and I'm having the following issue. I think the something is wrong with data model on TransactionResponse class, but not sure yet. java.io.EOFException: End of input at line 1 column 1 path $ in Android retrofit My call request is as follows. @FormUrlEncoded @POST("/ifapi.php") Call<TransactionResponse> loadData(@Field("user") TransactionRequest user); TransactionRequest class : import javax.annotation.Generated; @Generated("org

java.io.EOFException: End of input at line 1 column 1 path $ in Android retrofit

本小妞迷上赌 提交于 2020-07-06 19:29:27
问题 I'm using Retrofit to consume a REST API endpoint, and I'm having the following issue. I think the something is wrong with data model on TransactionResponse class, but not sure yet. java.io.EOFException: End of input at line 1 column 1 path $ in Android retrofit My call request is as follows. @FormUrlEncoded @POST("/ifapi.php") Call<TransactionResponse> loadData(@Field("user") TransactionRequest user); TransactionRequest class : import javax.annotation.Generated; @Generated("org

Same field has two different types gives trouble with Gson converter for Retrofit 2

烈酒焚心 提交于 2020-07-06 10:39:49
问题 Here is the json schema: As you can see, rated can be both boolean and object. I am using Retrofit 2 and Gson converter. How should I create my model for this schema? 回答1: Here's how I solved this issue: Create a custom type adapter in your model and parse rated manually; public class AccountState { //@SerializedName("rated") //NOPE, parse it manually private Integer mRated; //also don't name it rated public Integer getRated() { return mRated; } public void setRated(Integer rated) { this

How do I construct and pass raw json data with okHttpClient in android

醉酒当歌 提交于 2020-07-06 05:29:45
问题 I am using a query where I need to POST to an endpoint with okhttpclient. The issue is I have the payload value and the senttime. I just don't know how to create a json object to send over as a raw body object to the endpoint. To make things more clear: here's my postman screenshot: enter image description here This is my post request : https://example.org/api/service-profile/v1/device-notification/ {deviceId} Now I am planning to pass {deviceId} in the path, authorization token in the header