retrofit

Android Retrofit + GSON - Enum serialization for API calls - Annoying extra quotation marks added

最后都变了- 提交于 2020-01-05 03:07:31
问题 This problem (this might be by design, who knows - not simple to find a clear answer, at any rate) occurs in both Android Retrofit 1.9 and 2.0, and with the latest GSON library. I have an Enum class like such: public enum SomethingType { @SerializedName("first") First, @SerializedName("second") Second } And using Retrofit (2.0, but same issue with 1.9) along with GSON, I attempt to output the enum instance as such: @Multipart @POST("things") Call<ThingResponse> createThing( @Part("image")

Android connection with ESP8266 on One Plus ( Android 6.0.1)

≯℡__Kan透↙ 提交于 2020-01-04 09:36:35
问题 Retrofit on Android 6.0 has a problem making Http calls after connecting to Access Point Steps to reproduce: Connect to Esp8266 Access Point Make an http call to http://192.168.4.1 (Default gateway of esp8266 accesspoint) The IP address of WIFI is 192.168.4.2 It throws the below exception I have tried the same on Android 5.1 and the same code works flawlessly java.net.SocketException: socket failed: ENONET (Machine is not on the network) at libcore.io.IoBridge.socket(IoBridge.java:619) at

How do i store the json response from my server to an arraylist and pass to next activity?

◇◆丶佛笑我妖孽 提交于 2020-01-04 07:51:23
问题 I am using Retrofit and the server returns JSON object as response. I want to store it in an ArrayList and pass it to the next activity where it can be displayed in RecyclerView . I am not getting any error but there is no output on the Display activity. What could be the problem? Here is my main activity. public class MainActivity extends AppCompatActivity { public static final String ROOT_URL = "http://walletuncle.com/"; String username; String password; private Button makerequest; private

Retrofit 2 error: NetworkOnMainThreadException

我与影子孤独终老i 提交于 2020-01-04 06:51:06
问题 I'm trying to do a synchronous request to my server in Android. (Code works flawlessly in a plain Java project) I know that sync requests shouldn't be done on the main thread, so I start a new thread where the networking is done. I also know that it is possible to do Async-calls but a sync call fits my usecase better. bool networkingIsDoneHere(){ dostuff(); int number = doNetworkCall(); if(number < 500){ return true; } return false } The problem is that I still get the

Use Retrofit to parse text from JSON file in local

感情迁移 提交于 2020-01-04 06:17:09
问题 I have a JSON text file in /res/raw . After reading its text content, I would like to use Retrofit to parse JSON text to Object. But it seems Retrofit only accept input from file in server. Is there anyway to reuse Retrofit's JSON parser module in this case? 回答1: You can configure Gson instance once and then just use it both for local parsing and for Retrofit via RestAdapter.Builder.setConverter(new GsonConverter(customGson) 来源: https://stackoverflow.com/questions/26922591/use-retrofit-to

Using Retrofit and RxJava, how do I deserialize JSON when it doesn't map directly to a model object?

怎甘沉沦 提交于 2020-01-04 05:41:16
问题 The API I'm working with returns objects (and their containing objects) in a "flat" format and I'm having trouble getting this to work elegantly with Retrofit and RxJava. Consider this JSON response for an /employees/{id} endpoint: { "id": "123", "id_to_name": { "123" : "John Doe" }, "id_to_age": { "123" : 30 } } Using Retrofit and RxJava, how do I deserialize this to a Employee object with fields for name and age ? Ideally I'd like RxJava's onNext method to be called with an Employee object.

How to POST raw whole JSON in the body of a Retrofit request?

不问归期 提交于 2020-01-04 05:38:29
问题 This question may have been asked before but no it was not definitively answered. How exactly does one post raw whole JSON inside the body of a Retrofit request? See similar question here. Or is this answer correct that it must be form url encoded and passed as a field? I really hope not, as the services I am connecting to are just expecting raw JSON in the body of the post. They are not set up to look for a particular field for the JSON data. I just want to clarify this with the restperts

RETROFIT how to parse this response

痴心易碎 提交于 2020-01-04 05:31:08
问题 I'm trying to parse this json response yahoo yql with Retrofit,but the problem is that the response begins(as you can see in the link above) with the following characters: "finance_charts_json_callback(". Therefore i get the following error: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ . Is posible to parse this json file with Retrofit? Thanks in advance 回答1: It returns a json that's invoked by a callback

Repeatedly make API call with retrofit and rxjava

馋奶兔 提交于 2020-01-04 03:59:34
问题 I have a retrofit observable: @GET("something/") Observable<Something> getSomething(); subscribing to it gives the response. getSomething().subscribe(new Subscriber<Something>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { } @Override public void onNext(Something something) { //update database of something } }); how can i make this call every 60 seconds so that i can update database accordingly? 回答1: First please don't do it if you can avoid it. It's

How to handle pagination with Retrofit 2 and RxJava

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-03 17:19:29
问题 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":