retrofit

What is extra in URL while working with GET request? [closed]

允我心安 提交于 2020-02-08 10:59:44
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 hours ago . https://newsapi.org/v2/top-headlines?sources=bbc-news&apiKey=4e96bad47fc04e949a484544f7f74e6ff1 I'm working with retrofilt and this get request to fetch data. Now in this above url, Base URL is: https://newsapi.org/v2/ then what is end point in this case? top-headlines or bbc-news

How to register custom TypeAdapter or JsonDeserializer with Gson in Retrofit?

家住魔仙堡 提交于 2020-02-06 07:30:06
问题 I am using Retrofit in my project and I need some custom deserialization with some of the responses that the API I use returns. Just for an example: I receive JSON like: { "status": "7 rows processed" } ( will be "0 rows processed" if request failed ) and I need to deserialize to an object like: @Getter @RequiredArgsConstructor public static class Result { private final boolean success; } I have created custom deserializer: public class ResultDeserializer implements JsonDeserializer<Result> {

Sending ArrayList<Object> POST request with Retrofit

牧云@^-^@ 提交于 2020-02-04 01:19:07
问题 I want to send something like this to server { "InoorPersonID": "", "Discount": 0, "DiscountDescription": "", "Description": "", "OrderDetailList": [ { "ProductID": 0, "Amount": 0 } ], "ClientId": "", "ClientSecret": "" } and this is my service interface public interface StoreRetrofitSalesService { @FormUrlEncoded @POST(ServiceUrl.URL_ORDER_SET) Call<ServiceResult<Integer>> orderSet(@Field("OrderDetailList") ArrayList<OrderDetail> orderDetails, @Field("Discount") String discount, @Field(

Method invocation may produce NullPointerException Retrofit Body

微笑、不失礼 提交于 2020-02-03 03:59:05
问题 I am using Retrofit 2 for get response from my API and store its value in my constant like below if(response.isSuccessful()) { constant.banner_on = response.body().getBanner_on(); constant.int_on = response.body().getInt_on(); constant.int_click = response.body().getInt_click(); } its giving me warning on all three like below Method invocation getBanner_on may produce java.lang.nullPointerException I am confused and unable to resolve this warning. Let me know if someone can help me to come

Method invocation may produce NullPointerException Retrofit Body

只愿长相守 提交于 2020-02-03 03:58:50
问题 I am using Retrofit 2 for get response from my API and store its value in my constant like below if(response.isSuccessful()) { constant.banner_on = response.body().getBanner_on(); constant.int_on = response.body().getInt_on(); constant.int_click = response.body().getInt_click(); } its giving me warning on all three like below Method invocation getBanner_on may produce java.lang.nullPointerException I am confused and unable to resolve this warning. Let me know if someone can help me to come

java.lang.illegalstateException:Expected BEGIN_OBJECT but was BEGIN_ARRAY Retrofit

喜欢而已 提交于 2020-01-30 11:47:07
问题 i got error java.lang.illegalstateException:Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 42 when Call API with retrofit, here is my code : Here is my interface : @FormUrlEncoded @POST("myCollection") Call<APIResponse<List<MyCollection>>> getMyCollection( @Field("caller_id") String caller_id ); Here is for Call : public class UploadVideoToneActivity extends BaseActivity{ List<MyCollection> collection = new ArrayList<>(); private void loadCollection() { ContactItem callerID =

java.lang.illegalstateException:Expected BEGIN_OBJECT but was BEGIN_ARRAY Retrofit

送分小仙女□ 提交于 2020-01-30 11:46:27
问题 i got error java.lang.illegalstateException:Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 42 when Call API with retrofit, here is my code : Here is my interface : @FormUrlEncoded @POST("myCollection") Call<APIResponse<List<MyCollection>>> getMyCollection( @Field("caller_id") String caller_id ); Here is for Call : public class UploadVideoToneActivity extends BaseActivity{ List<MyCollection> collection = new ArrayList<>(); private void loadCollection() { ContactItem callerID =

OkHttpClient throws exception after upgrading to OkHttp3

本小妞迷上赌 提交于 2020-01-28 17:40:23
问题 I'm using following lines of code to add a default header to all of my requests sent using Retrofit2: private static OkHttpClient defaultHttpClient = new OkHttpClient(); static { defaultHttpClient.networkInterceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request().newBuilder() .addHeader("Accept", "Application/JSON").build(); return chain.proceed(request); } }); } After upgrading retrofit to beta-3 version, I

OkHttpClient throws exception after upgrading to OkHttp3

人盡茶涼 提交于 2020-01-28 17:40:15
问题 I'm using following lines of code to add a default header to all of my requests sent using Retrofit2: private static OkHttpClient defaultHttpClient = new OkHttpClient(); static { defaultHttpClient.networkInterceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request().newBuilder() .addHeader("Accept", "Application/JSON").build(); return chain.proceed(request); } }); } After upgrading retrofit to beta-3 version, I

Retrofit REST client for Android and Java does not terminate

∥☆過路亽.° 提交于 2020-01-28 11:23:51
问题 I am investigating the Retrofit REST client for Android and Java. Using a standard Java project within Eclipse I am using @POST with void return type. Making Asynchronous calls. Everything works as expected, however my test main method never terminates. I have to manually stop each test execution. What do I need to do (or stop doing) so that my tests terminate automatically? Here's my java code. import retrofit.Callback; import retrofit.RestAdapter; import retrofit.RetrofitError; import