retrofit2

Get difference types of JSON response Retrofit

风流意气都作罢 提交于 2019-12-08 12:57:42
问题 I have REST api which respond according to current state at the same path. Let's assume /api/users response with { "status":200, "error":false, "users":["a","b"] } if user is authorised. Else if user is not authorised it respond with {"status":403,"error":true,"redirect":"url"} . When defining Interface for api calls with Retrofit it needs the exact type of response object. Ex: @GET("users") Call<List<User>> getUsers() But here API server respond with different shapes of object. How to handle

RxJava2 how to update existing subscription when request parameter changes

不羁的心 提交于 2019-12-08 08:14:32
问题 I have an activity on which I make a network request everytime the user input changes. The api definition is as follows: interface Api { @GET("/accounts/check") fun checkUsername(@Query("username") username: String): Observable<UsernameResponse> } Then the services that manages it all: class ApiService { var api: Api init { api = retrofit.create(Api::class.java) } companion object { val baseUrl: String = "https://someapihost" var rxAdapter: RxJava2CallAdapterFactory =

How to maintain same DataSource for List,Filter and Search in Android Paging Library

喜夏-厌秋 提交于 2019-12-08 07:45:03
问题 I am having activity that displays list of items and also having filter and search option. I am displaying the items using android paging library. First time the List of items will be loaded its working fine when I am Scrolling to bottom next set of items getting loaded. But I also want to filter the items and Search the items. On Filtering or Searching item I am invalidating the existing source.if am not invalidate the Data Source the filter and Search api is not firing.I want to load list

Why I get Attribute value must be constant error?

谁说我不能喝 提交于 2019-12-08 07:27:10
问题 I'm trying to add current date to url String in HTTP @GET, but I'm getting Attribute value must be constant error. I can't figure why? I'm using retrofit 2. public interface API { final Date c = new Date(); final String date=new SimpleDateFormat("yyyy-MM-dd").format(c); static final String url = ("/modules/json/json/Index?costNumber=0417&firstDay="+date+"&language=fi"); @GET(url) Call<Menu> getMenuName(); 回答1: As @Selvin already pointed out in the comments it's because of date not being a

i tried to post jsonobject in retrofit

不羁岁月 提交于 2019-12-08 07:23:04
问题 hi i tried to post the json data to server using retrofit interface @POST("something") Call<Test_Responce> testRes (@Body JSONObject paramObject); function try { JSONObject paramObject = new JSONObject(); paramObject.put("test_id", 5); paramObject.put("user_id", "null"); paramObject.put("org_id", 2); paramObject.put("schedule_id", 15); paramObject.put("group_id", "null"); JSONObject current_section = new JSONObject(); paramObject.put("current_section",current_section); Call<Test_Responce>

How to upload image with Retrofit Android?

大城市里の小女人 提交于 2019-12-08 06:44:49
问题 I have a function to request upload image with Retrofit like this void uploadPhoto(File file) { RequestBody photo = RequestBody.create(MediaType.parse("application/image"), file); RequestBody body = new MultipartBuilder() .type(MultipartBuilder.FORM) .addFormDataPart("photo", file.getName(), photo) .build(); fragment.showProgressDialog(fragment.loading); fragment.getApi().uploadPhoto(PrefHelper.getString(PrefKey.TOKEN), body) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers

Unable to create POJO with Retrofit and Java in android

半城伤御伤魂 提交于 2019-12-08 06:33:49
问题 I am getting following json response from one of the vendor. { "status": "success", "data": { "values": [ [ "2015-12-28T09:15:00+0530", 1386.4, 1388, 1381.05, 1385.1, 788 ], [ "2015-12-28T09:15:00+0530", 1386.4, 1388, 1381.05, 1385.1, 788 ] ] } } I would like to convert this to POJO. I am using retrofit 2.0, rx java. I have tried following public class HistoricalDataContainer implements Parcelable{ public String status; public CandleList data; protected HistoricalDataContainer(Parcel in) {

How to handle object on onResponse of retrofit 2.0

会有一股神秘感。 提交于 2019-12-08 06:09:37
问题 This is my logic for getting response in retrofit 2.0 call.enqueue(new Callback<ArrayList<Wallet>>() { @Override public void onResponse(Response<ArrayList<Wallet>> response, Retrofit retrofit) { if (response.isSuccess()) { // use response data and do some fancy stuff :) loading.dismiss(); ArrayList<Wallet> orders = response.body(); Utility.displayToast("Wallet size is" + orders.size()); } else { } } }); Data format from rest API is like this: [ { "description": "Cashback", "amount": "20.00",

Retrofit 2.0 delete, put are not working

亡梦爱人 提交于 2019-12-08 05:43:54
问题 I am giving a try to use Retrofit 2.0 to implement a library system. Which can add book, list all book info, list one book info, delete one book, delete all books, update one book info. My baseURL has a ' / ' in its end: http://www.example.com/webservice/ The first three features work very well: @GET("books") Call<ArrayList<Book>> listBooks(); @POST("books") Call<Book> addBook(@Body Book book); @GET("books/{id}") Call<Book> getBookInfo(@Path("id") int bookId); However, those three don't work

How can i POST json data in Android

≡放荡痞女 提交于 2019-12-08 05:15:38
问题 In my application I want POST some data, and this data get users and POST to server. For server requests I use Retrofit2 . For POST this data I should POST with json format, such as this : { "email": "example@example.com", "username": "example", "password": "123", } After POST data I should check with this results for submit data has Ok ro Not. { "status": 200, "Message": "", "data": true } I give Email, Username and Password with EditText from users, but how can I POST this data to server