retrofit

How can I return value from function onResponse of Retrofit?

南笙酒味 提交于 2019-12-17 18:11:17
问题 I'm trying to return a value that i get from onResponse method in retrofit call request, is there a way that i can get that value out of the overrided method? here is my code: public JSONArray RequestGR(LatLng start, LatLng end) { final JSONArray jsonArray_GR; EndpointInterface loginService = ServiceAuthGenerator.createService(EndpointInterface.class); Call<GR> call = loginService.getroutedriver(); call.enqueue(new Callback<GR>() { @Override public void onResponse(Response<GR> response ,

How can Retrofit 2.0 parse nested JSON object?

假装没事ソ 提交于 2019-12-17 18:07:33
问题 Our team decide to use Retrofit 2.0 and I'm doing some initial research on this library. As stated in the title, I want parse some nested JSON objects via Retrofit 2.0 in our Android app. For example, here is a nested JSON object with the format: { "title": "Recent Uploads tagged android", "link": "https://www.flickr.com/photos/tags/android/", "description": "", "modified": "2015-10-05T05:30:01Z", "generator": "https://www.flickr.com/", "items": [ { "title": ... "link": ... "media": {"m":

How to implement an async Callback using Square's Retrofit networking library

南笙酒味 提交于 2019-12-17 17:44:12
问题 As an iOS developer beginning to work with Android I came across Retrofit. I understand how to implement synchronous requests but am having trouble implementing asynchronous requests with success/failure callbacks. Specifically, the Callback syntax is unclear to me and there are no concrete examples of how to do this on the Retrofit website, the Square blogpost introducing Retrofit, or elsewhere that I've seen. Can someone please post some example code on this? I filed an issue in the

Square retrofit server mock for testing

痞子三分冷 提交于 2019-12-17 17:28:13
问题 What's the best way to mock a server for testing when using the square retrofit framework. Potential ways: Create a new retrofit client and set it in the RestAdapter.Builder().setClient(). This involves parsing the Request object and returning the json as a Response object. Implement this annotated interface as a mock class and use that in place of the version provided by RestAdapter.create() (wont test gson serialisation) ? Ideally I want to have the mocked server provide json responses so I

RxJava and Retrofit2: NetworkOnMainThreadException

余生长醉 提交于 2019-12-17 16:33:36
问题 I realize that I am using subscribeOn()/observeOn() on the MainThread. What are the set of options I can pass into subscribeOn()? What are the set of options I can pass into observeOn()? 12-17 21:36:09.154 20550-20550/rx.test D/MainActivity2: [onCreate] 12-17 21:36:09.231 20550-20550/rx.test D/MainActivity2: starting up observable... 12-17 21:36:09.256 20550-20550/rx.test D/MainActivity2: [onError] 12-17 21:36:09.256 20550-20550/rx.test W/System.err: android.os.NetworkOnMainThreadException

Need help in POST multiple image file using retrofit?

早过忘川 提交于 2019-12-17 15:46:31
问题 How to add multiple images/files on a same parameter along with other textual data using retrofit? Single image is uploading perfectly using following interface @Multipart @POST("/users/updateProfile/") public void updateProfileWithImage( @Part("user_id") TypedString first_name, @Part ("image") TypedFile image, Callback<WebResponse> callback); 回答1: You can use the @MultiPart Post with @PartMap as parameter Map<String, TypedFile> files = new HashMap<String, TypedFile>(); files.put("my file

Stack overflow when using Retrofit rxjava concatWith

谁说胖子不能爱 提交于 2019-12-17 15:44:53
问题 I want to handle pagination in Retrofit using rxjava Observable. I followed the advice from another question. I have more than 100 pages that needs to be fetched, but chain fails around the 20th page and stops any further subscription to the observable with the below log in the logcat 04-04 04:12:11.766 2951-3012/com.example.app I/dalvikvm﹕ threadid=28: stack overflow on call to Ljava/util/concurrent/atomic/AtomicLongFieldUpdater$CASUpdater;.compareAndSet:ZLJJ 04-04 04:12:11.766 2951-3012/com

Retrofit and GET using parameters

久未见 提交于 2019-12-17 10:34:05
问题 I am trying to send a request to the Google GeoCode API using Retrofit. The service interface looks like this: public interface FooService { @GET("/maps/api/geocode/json?address={zipcode}&sensor=false") void getPositionByZip(@Path("zipcode") int zipcode, Callback<String> cb); } When I call the service: OkHttpClient okHttpClient = new OkHttpClient(); RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(Constants.GOOGLE_GEOCODE_URL).setClient(new OkClient(okHttpClient)).build();

How to parse JSON array without any object in Retrofit?

我只是一个虾纸丫 提交于 2019-12-17 09:56:25
问题 I am working with Retrofit and GSON. I have a JSON response as a JSON array but I don't know how to parse it by using a model class. My response is as follows: [ "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight" ] 回答1: Just call in the callback a list of Strings and it should do the job... new Callback<List<String>>(). 来源: https://stackoverflow.com/questions/28628513/how-to-parse-json-array-without-any-object-in-retrofit

Auth 1.0 oauth_signature creation Android for magento API

回眸只為那壹抹淺笑 提交于 2019-12-17 07:50:26
问题 I call the Magento API with the following Autherization as header, auth = "OAuth oauth_consumer_key=**********************,oauth_consumer_secret=****************,oauth_token=************,oauth_token_secret=**************,oauth_signature_method=HMAC-SHA1,oauth_timestamp=" + ConstantFunctions.GetTimeStamp() + ",oauth_nonce=" + ConstantFunctions.GetNonce() + ",oauth_signature=*******************) ; While I call the API, Getting error oauth_problem=signature_invalid .All other parameters validate