retrofit

Handle different JSON response types from same endpoint in RetroFit

不问归期 提交于 2019-12-19 17:15:11
问题 I need help. I have an endpoint that takes a parameter. Depending on this parameter, the JSON returned will be completely different. Is it possible for RetroFit to handle this? For example: http://myserver.com/all/<parameter> where parameter is BUS or BICYCLE , as well as adding others later. An example BUS request will return: "stops": [{ "Lat": "....", "Lng": "....", "Name": "Main Street", "Route": "", "StopNumber": "2" }] The BICYCLE endpoint will return: "stops": [{ "address": "Town

Runtime Execption java.lang.NoClassDefFoundError: retrofit2.Platform in Android

孤街浪徒 提交于 2019-12-19 08:29:34
问题 i am using Rtofit to handling the Serverside Data from Mobile After Implementing the Retrofit I am Getting the below Exception any know about this issue tell me where i am did wrong Init Retrofit: mRetrofit = new Retrofit.Builder() .baseUrl(AppConstance.APP_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); Iservice = mRetrofit.create(IdeaService.class); Gradle File dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com

App crash on HttpLoggingInterceptor

喜夏-厌秋 提交于 2019-12-19 06:53:36
问题 I've created project with Retrofit 2, okhttp and okhttp:logging-interceptor. private static APIInterface apiInterface; private static RestClient restClient; private static HttpLoggingInterceptor interceptor; OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setConnectTimeout(30, TimeUnit.SECONDS); okHttpClient.setReadTimeout(30, TimeUnit.SECONDS); okHttpClient.interceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request

App crash on HttpLoggingInterceptor

孤街浪徒 提交于 2019-12-19 06:51:38
问题 I've created project with Retrofit 2, okhttp and okhttp:logging-interceptor. private static APIInterface apiInterface; private static RestClient restClient; private static HttpLoggingInterceptor interceptor; OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setConnectTimeout(30, TimeUnit.SECONDS); okHttpClient.setReadTimeout(30, TimeUnit.SECONDS); okHttpClient.interceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request

Retrofit初识

不问归期 提交于 2019-12-19 04:55:07
Retrofit Retrofit是一套RESTful架构的Android(Java)客户端实现,基于注解,提供JSON to POJO(Plain Ordinary Java Object,简单Java对象),POJO to JSON,网络请求(POST,GET,PUT,DELETE等)封装。 相关资料: RESTful百度百科 RESTful API设计 Retrofit 原理 Retrofit 简单使用 Retrofit Github工程地址 Retrofit 和Java领域的ORM概念类似, ORM把结构化数据转换为Java对象,而Retrofit 把REST API返回的数据转化为Java对象方便操作。同时还封装了网络代码的调用。 例如: public interface GitHubService { @GET("/users/{user}/repos") List<Repo> listRepos(@Path("user") String user); } 定义上面的一个REST API接口。 该接口定义了一个函数 listRepos ,该函数会通过HTTP GET请求去访问服务器的 /users/{user}/repos 路径并把返回的结果封装为 List<Repo> Java对象返回。 其中URL路径中的 {user} 的值为 listRepos 函数中的参数

retrofit 2.0 xml simplexml converter issue while having retrolambda in gradle file

≯℡__Kan透↙ 提交于 2019-12-19 04:08:04
问题 Here is my gradle file apply plugin: 'com.android.application' apply plugin: 'me.tatarka.retrolambda' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.demo.sample" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility

Get String response body from retrofit2

一曲冷凌霜 提交于 2019-12-19 04:05:31
问题 I am using retrofit1 old style @GET("/loginUser") public Call<Response> login( @Query("email") String email, @Query("password") String password, Callback<Response> callback); Now i don't want to get "User" class however i want to get a String response. Previously we were using "Response" However there is no Response in retrofit2, How can i get string response or full body response from the server without using any json parsing? 回答1: Create this class import java.io.IOException; import java

Coverting json array using retrofit?

寵の児 提交于 2019-12-19 02:47:10
问题 this is my Json [ { "nata_center":{ "id":67, "nata_center_name":"Primo Institute of Design" } }, { "nata_center":{ "id":68, "nata_center_name":"Sai Ganesh Institute" } } ] Pojo classes public class Explorer { NataCenter nataCenter; public NataCenter getNataCenter() { return nataCenter; } public void setNataCenter(NataCenter nataCenter) { this.nataCenter = nataCenter; } } 2) public class NataCenter { public String id; public String nata_center_name; public NataCenter(String id,String nata

How do I convert a successful Response body to a specific type using retrofit?

故事扮演 提交于 2019-12-18 19:21:43
问题 In async mode retrofit calls public void success(T t, Response rawResponse) were t is the converted response, and rawResponse is the raw response. This provides you with access to both the raw response and the converted response. In sync mode you can get either the converted response OR the raw response converted response @GET("/users/list") List<User> userList(); raw response @GET("/users/list") Response userList(); The Response object does have a method to get the body TypedInput getBody()

Get html of a website with retrofit - Android?

ぐ巨炮叔叔 提交于 2019-12-18 16:51:41
问题 How can I get html of a website with retrofit ? for example I have this url and I need to get html of this url and how can I load more . Bellow is my code : MainActivity.java: public class MainActivity extends AppCompatActivity { TextView txt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txt = (TextView) findViewById(R.id.txt); OkHttpClient okHttpClient = new OkHttpClient().newBuilder() .build();