retrofit2

Get JSON object one by one from JSON array in Android using Retrofit and RxJava

廉价感情. 提交于 2019-12-07 04:29:19
问题 I am using retrofit to hit my network api which returns json array. I am doing so using following code- Observable<MyJson[]> response = (Observable<MyJson[]>)mNetworkService.getReadyObserverable(mNetworkService.getNetworkServiceApi().getMyDataJsons(), MyJson.class, true, useCache); mAirlineSubscription = response.subscribe(new Observer<MyJson[]>() { @Override public void onCompleted() { Log.d(TAG, "getData completed.."); } @Override public void onError(Throwable e) { Log.e(TAG, "onError: " +

Okhttp ignores Dispatcher setting when used with Retrofit RxJavaCallAdapterFactory

…衆ロ難τιáo~ 提交于 2019-12-07 03:26:54
问题 Consider the following initializations of OkHttp and Retrofit: public static SomeServiceRestInterface newRestService(String apiUrl) { Retrofit retrofit = new Retrofit.Builder() .baseUrl(apiUrl) .client(createOkHttpClient()) .addCallAdapterFactory(RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io())) .addConverterFactory(createGsonConverter()) .build(); return retrofit.create(SomeServiceRestInterface.class); } private static OkHttpClient createOkHttpClient() { Dispatcher dispatcher =

Cannot POST multipart data from retrofit 2

假装没事ソ 提交于 2019-12-07 01:35:46
问题 I have to send a post request in this format. --__X_PAW_BOUNDARY__ Content-Disposition: form-data; name="user_photo[image]"; filename="file.jpg" Content-Type: image/jpeg ÿØÿàJFIFHHÿáLExifMM*i ÿí8Photoshop 3.08BIM8BIM%ÔÙ²é ìøB~ÿÀ "ÿÄ ÿĵ}!1AQa"q2¡#B±ÁRÑð$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖרÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ ÿĵw!1AQaq"2B¡±Á #3RðbrÑ $4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖרÙÚâãäåæçèéêòóôõö÷øùúÿÛC ÿÛC

Store data into Realm through Retrofit 2

☆樱花仙子☆ 提交于 2019-12-06 21:04:31
I am new for Realm integration. I am trying to save my retrofit json response into Realm database. But still I am confuse how to complete this task for retrofit 2. I am getting json response and extends RealmObject class as per RealM documents. but still not getting any good way to store my response into realm directly. Dashboard Activity: apiInterface = APIClient.getClient().create(APIInterface.class); final Call<RealmList<ExampleTest>> call = apiInterface.getSurvay(); call.enqueue(new Callback<RealmList<ExampleTest>>() { @Override public void onResponse(Call<RealmList<ExampleTest>> call,

Turn string date from json to a Date object with Moshi

寵の児 提交于 2019-12-06 20:27:42
问题 with Gson you would do this Gson gson = new GsonBuilder() .setDateFormat("yyyy-MM-dd'T'HH:mm") .create(); and pass it to the retrofit builder and Gson would make a Date object for you, Is there some way to get Moshi to do this too in a kotlin class? 回答1: If you’d like to use a standard ISO-8601/RFC 3339 date adapter (you probably do) then you can use the built-in adapter: Moshi moshi = new Moshi.Builder() .add(Date.class, new Rfc3339DateJsonAdapter().nullSafe()) .build(); JsonAdapter<Date>

Retrofit is returning cached response

烈酒焚心 提交于 2019-12-06 16:56:53
I am using Retrofit in an Android application. When I hit an API with token to get user information it gives cached(previous) response. Whenever I logged out and log in again API gives previous user detail, I tested API in Postman it works fine there. I have tried some solutions I searched but nothing is working. Response header that I am getting is Transfer-Encoding: chunked Content-Type: application/json; charset=utf-8 Server: Kestrel Date: Mon, 08 Jan 2018 09:35:26 GMT Below is ApiClient class public class ApiClient { public static final String BASE_URL = "http://XX.XXX.XXX.XX/api/";

Unable to create POJO with Retrofit and Java in android

和自甴很熟 提交于 2019-12-06 16:11:52
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) { status = in.readString(); data = in.readParcelable(CandleList.class.getClassLoader()); } @Override public

Retrofit data persistence

不羁的心 提交于 2019-12-06 15:20:15
问题 How do I persist the data that has been parsed from the server using Retrofit library. So that users can view it when there is no internet connection. final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.post_recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(this)); ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class); Call<ArrayList<Post>> call = apiService.getAllPosts(); call.enqueue(new Callback<ArrayList<Post>>() { @Override public

i tried to post jsonobject in retrofit

谁说我不能喝 提交于 2019-12-06 14:57:22
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> userCall = api_interface.testRes(paramObject); userCall.enqueue(new Callback<Test_Responce>() { @Override

How to combine Retrofit 2 with Realm and RxJava

大兔子大兔子 提交于 2019-12-06 14:02:27
I want to save retrofit responses to realm on the background thread then pass it to the UI Thread, but its a bit tricky since Realm is very touchy with threads. so the code would look like something like this, please submit your edits to all better solutions :) restApi.userRealmList() .doOnNext(userRealmModels -> { if (userRealmModels != null){ mRealm = Realm.getInstance(mContext); mRealm.asObservable() .map(realm -> mRealm.copyToRealmOrUpdate(userEntity)) .subscribe(new Subscriber<Object>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { e