retrofit2

Retrofit parse JSON dynamic keys

大憨熊 提交于 2019-12-03 16:07:13
I'm a newbie in Retrofit. How to parse the Json below using retrofit? { "data": { "Aatrox": { "id": 266, "title": "a Espada Darkin", "name": "Aatrox", "key": "Aatrox" }, "Thresh": { "id": 412, "title": "o Guardião das Correntes", "name": "Thresh", "key": "Thresh" } }, "type":"champion", "version":"6.23.1" } You could make your model POJO contain a Map<String, Champion> to deserialize into, to deal with the dynamic keys. Example: public class ChampionData { public Map<String, Champion> data; public String type; public String version; } public class Champion { public int id; public String title;

No Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 15:20:18
问题 I am trying to consume an API using retrofit and jackson to deserializitation. The error present in the title "No Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator" appear in the onFailure. This is the JSON I want to fetch: { "data": { "repsol_id": "1129", "name": "ES-MASSAMÁ", "latitude": "38.763733333", "longitude": "-9.258619444000001", "address": "RUA GENERAL HUMBERTO DELGADO, LT.16", "post_code": "2745-280", "location":

How to get the request url in retrofit 2.0 with rxjava?

蹲街弑〆低调 提交于 2019-12-03 14:53:23
问题 I'm trying to upgrade to Retrofit 2.0 and add RxJava in my android project. I'm making an api call and want to retrieve the url and it with the response data in sqlite as a cache Observable<MyResponseObject> apiCall(@Body body); And in the RxJava call: myRetrofitObject.apiCall(body).subscribe(new Subscriber<MyResponseObject>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { } @Override public void onNext(MyResponseObject myResponseObject) { } }); In

Retrofit JSON deserializing object's $ref reference to its original copy

こ雲淡風輕ζ 提交于 2019-12-03 14:11:02
I am using Microsoft.Net with Breeze for APIs and the results I get using Retrofit have nested repeated same objects. For example EmployeeJob has Customer navigation property so the APIs result looks like this { Id:1, "Customer_Id": 39, "Customer": { "$id": "2", "$type": "Wit.Trade.Entities.Customer, Wit.Trade", "CourtesyTitle": "Mr", "FirstName": "Ahmad" } } { Id:2 "Customer_Id": 39, "Customer": { "$ref": "2" //here same customer Ahmad }, } Now the Java List I get of these EmployeeJobs has only Customer in the first record and others have nothing. How can I map the $ref:"2" to its original

你真的会用Retrofit2吗?Retrofit2完全教程

孤人 提交于 2019-12-03 14:06:52
本文注目录: Retrofit入门 Retrofit注解详解 Gson与Converter RxJava与CallAdapter 自定义Converter 自定义CallAdapter 其它说明 前言 本文中的Retrofit均指代Retrofit2.0。 本文涉及到的代码以及测试使用的接口可在 Github 上找到。 测试接口服务器在 server 项目下,直接运行 RESTServer.main() 即可启动测试服务器,所面代码示例均使用该接口(接口地址 http://localhost:4567/ ). 当然你也可以自己借助 json-server 或 最新开源的 Parse 搭建一个REST API,不过都需要安装Node.js,有兴趣的可以去试试。 接口列表: 地址 请求方法 参数 说明 /blog GET page={page},sort=asc或desc 分页获取Blog列表,每页10条 /blog/{id} GET id 获取指定ID的Blog /blog POST {"author":"","title":"","content":""} 创建一个新Blog /blog/{id} PUT {"author":"","title":"","content":""} 中至少一个 修改Blog /blog/{id} DELETE id 删除一个Blog /form

Retrofit 2 returns null in release APK when minifyenable but ok in debug APK

你。 提交于 2019-12-03 13:29:57
Getting null response but code 200 with Release APK when minify enable, when minify false then its ok. But Getting expected response with debug APK when minify enable. Problem solved :) No issue with proguard-rules no need to add anything extra. Needed to add SerializedName annotation if minifyEnabled even if variable name same as key. That was the only Model which i had created manually :P Which works fine in Debug but not after Signed in. :) You need to setup proguard-rule for release. If you want to test real server, you can create new build type, which targets server API Cheers :) I had

Upload file in Retrofit 2

醉酒当歌 提交于 2019-12-03 12:40:25
问题 I tried the following but on response i am getting 500 error (Internal Server Error) -- help me design the interface for the request in the above screenshot...thanks @Multipart @POST("myrecord") Call<ResponseBody> addRecord(@Query("token") String token,@Query("userid") int userId, @Query("name") String name, @Part("file") RequestBody file); File file = new File(getRealPathFromURI(data.getData())); RequestBody requestFile = RequestBody.create(MediaType.parse("image/*"), getRealPathFromURI(data

Is it possible to use retrofit without model class?

此生再无相见时 提交于 2019-12-03 12:38:49
i have problem to use model class in retrofit lib. A backend side field name has changed. Is it possible to get response without model class? Yes, you can. @POST("url") Call<JsonObject> register(@Query("name") String name, @Query("password") String password); Just write JsonArray or JsonObject according to your response instead of Model class. Then, get data from JsonObject or JsonArray which you get in response as below Call<JsonObject> call = application.getServiceLink().register(); call.enqueue(new Callback<JsonObject>() { @Override public void onResponse(Call<JsonObject> call, Response

Gson deserialize interface to its Class implementation

人走茶凉 提交于 2019-12-03 12:31:08
I am using Retrofit 2.1.0 with converter-gson:2.1.0 and separately gson:2.6.2 in order to customize the serialization/deserialization. The problem is that my POJOs should be hidden behind interfaces and I want to tell Gson which class should be the deserialized interface. And after the deserialization/ serialization Retrofit should be able to return the interface. It would be good if I can take advantage of Generics and easily create a way to tell Gson or Retrofit to serialize/deserialize FooInterface to FooClass. Ajay Deshwal I am assuming that you want to create a single deserializer for all

Not able to load data from cache okHttp & retrofit

时光怂恿深爱的人放手 提交于 2019-12-03 12:30:19
Here is my code where i am calling api and also define cache for okhttp with retrofit: public class DemoPresenter { DemoView vDemoView; private Context mContext; public DemoPresenter(Context mcontext, DemoView vDemoView) { this.vDemoView = vDemoView; this.mContext = mcontext; } public void callAllProduct() { if (vDemoView != null) { vDemoView.showProductProgressBar(); } OkHttpClient okHttpClient = new OkHttpClient.Builder() .cache(new Cache(mContext.getCacheDir(), 10 * 1024 * 1024)) // 10 MB .addInterceptor(new Interceptor() { @Override public okhttp3.Response intercept(Chain chain) throws