天道酬勤,学无止境

retrofit

Retrofit 404 not found web api

I have a web api and an application. So I want to a Register app but I have a problem. I use the azure. There is my registerapi (interface) @FormUrlEncoded @POST("/application/json") public void insertUser( @Field("Username") String Username, @Field("Password") String Password, @Field("Email") String Email, Callback<Response> callback); and my mainactivty.java page public class MainActivity extends AppCompatActivity { private EditText editTextUsername; private EditText editTextPassword; private EditText editTextEmail; private Button buttonRegister; final public static String ROOT_URL = "http:/

2022-01-18 11:50:44    分类:问答    android   azure   http-status-code-404   retrofit

Simple custom mapping of JSON property to object property with Retrofit

What is the simplest way to define a custom mapping of a JSON property to a particular object property in RetroFit? Example JSON response for a set of "rewards": [ { "name" : "$5 Voucher", "description" : "Get $5 off your next purchase", "assets" : { "icon" : "icon.png" } } ] Reward class in my Android project: public class Reward { @SerializedName("name") private String name; @SerializedName("description") private String description; @SerializedName("icon") private String icon; } Because name and description map 1:1 with the server response, RetroFit has no issues performing the mapping, but

2022-01-18 10:45:18    分类:问答    android   json   gson   retrofit

Multiple enqueue in retrofit causing out of memory error?

Am doing my project using retrofit2. When my Call goes on failure i repeat same call again.Repeation of this call made my app to force close. When i look on log i got error log, which is given below. I felt this is caused by multiple enqueue to same Call. So i did that before enqueus i called cancel. But its not working. getting same force close. FATAL EXCEPTION: main Process: com.SocialMob, PID: 27846 java.lang.OutOfMemoryError: pthread_create (stack size 16384 bytes) failed: Try again at java.lang.VMThread.create(Native Method) at java.lang.Thread.start(Thread.java:1029) at java.util

2022-01-18 04:57:44    分类:问答    android   out-of-memory   retrofit   retrofit2

NoClassDefFoundError for retrofit.RestAdapter$Builder

I'm using Android Studio and I would like to use Retrofit, a rest client for Android and Java. I added retrofit in dependencies of my build.gradle file. So, I can use it on my project but when I would like to execute it, I have a NoClassDefFoundError for retrofit.RestAdapter$Builder inner class. dependencies { compile 'com.squareup.retrofit:retrofit:1.3.0' } Thanks in advance for your help. Edit for solution : Updates your Android Studio to 4.0+ Enables annotations in Preferences > Compiler > Annotation Processors > Enable Annotation processing.

2022-01-18 04:39:44    分类:问答    android   gradle   android-studio   android-gradle-plugin   retrofit

Deserialzing JSON with multiple types for a property

I am working with a 3rd party API that returns three different types for the same JSON property, depending one how many nested objects it contains. I'm trying to figure out the best way to handle deserializing these objects using Jackson (preferably with Retrofit). A simplified example: when retrieving a Customer record from this API, the response might be any one of: Customer has multiple phone numbers; returns an array of PhoneObjects { "Phones": { "PhoneObject":[ {"number":"800 555 6666","type":"Home"}, {"number":"800 555 4444","type":"Work"} ] } } Customer has one phone number; return a

2022-01-17 17:15:01    分类:问答    java   json   jackson   retrofit

Why is Retrofit adding a trailing slash to all URLs?

Editing question with more details : I understand the use of service interfaces in Retrofit. I want to make a call to a URL like this : http://a.com/b/c (and later append query parameters using a service interface). My limitations are : I cannot use /b/c as a part of service interface (as path parameter). I need it as a part of base url. I have detailed the reason below. I cannot afford to have a resultant call being made to http://a.com/b/c/?key=val. What I need is http://a.com/b/c?key=val (the trailing slash after "c" is creating problems for my API). More details below. My Server API

2022-01-17 10:32:20    分类:问答    android   retrofit

How to send FCM notification from android using Retrofit?

I am want send fcm notification from android device to another device , using retrofit . I try this but, public interface ApiInterface { @Headers("Authorization : key=AAAA4Ubio1Q:APA91bGWkw84b1XX2nnnOKn8MO25U2giLRXXXTUkXidojFluZk_qKXXXlS27oMZZV5goTQdwRtpdmvI1iAPRZZDNKz6c-mpU6nvHZJ-Jg9f1fQ5NdttftqUpqwAkObLEEX26VFDDbXN8") @POST("fcm/send") Call<ResponseBody> sendChatNotification(@Field("to") String token,@Body RequestNotificaton requestNotificaton); } i am getting this error java.lang.IllegalArgumentException: Unexpected char 0x20 at 13 in header name: Authorization at okhttp3.Headers$Builder

2022-01-17 08:33:55    分类:问答    android   retrofit   retrofit2

How to handle pagination with Retrofit 2 and RxJava

I know how to handle Retrofit responses but I have a problem with handling pagination from a REST API with rx java. Background The rest api that I'm using gives me the following response with the link to the next page in the headers: HTTP 200 OK Allow: GET, HEAD, OPTIONS Content-Type: application/json Link: <http://some-endpoint.com/pictures?page=2>; rel="next" Vary: Accept X-Total-Count: 80 [ { "id": 3, "url": "", "picture": { "id": 6, "url": "", "name": "Chrysler" }, "location": { "type": "Point", "coordinates": [ 10.108956, 41.389576000000005 ] } }, { "id": 4, "url": "", "picture": { "id"

2022-01-17 04:02:08    分类:问答    android   pagination   retrofit   rx-java   retrofit2

Reading JSON with Retrofit

I've got the following JSON feed: { collection_name: "My First Collection", username: "Alias", collection: { 1: { photo_id: 1, owner: "Some Owner", title: "Lightening McQueen", url: "http://hesp.suroot.com/elliot/muzei/public/images/randomhash1.jpg" }, 2: { photo_id: 2, owner: "Awesome Painter", title: "Orange Plane", url: "http://hesp.suroot.com/elliot/muzei/public/images/randomhash2.jpg" } } } What I am trying to do is get the contents of the collection - photo_id, owner, title and URL. I have the following code, however I am getting GSON JSON errors: @GET("/elliot/muzei/public/collection/

2022-01-17 04:01:08    分类:问答    java   android   json   retrofit

Retrofit Method invocation may produce 'java.lang.NullPointerException'

Using Retrofit 2.3.0 I am getting the following message in Android Studio Any suggestions on how I could remove this IDE error message. Thanks

2022-01-17 00:56:26    分类:问答    android   nullpointerexception   retrofit