When make GET request on this url I get JSON:
http://52.74.115.250:8080/api/orders?startDay=1&startYear=2017&startMonth=1&endYear=2018&endMonth=2&endDay=9&isAll=true"
When I tried this with the retrofit library in android I get this error:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
My code is below.
RetrofitClient.java
public class RetrofitClient {
public static Retrofit retrofit;
public static Gson gson;
public static Retrofit getClient(String baseUrl)
{
if(retrofit==null) {
gson = new GsonBuilder() .setLenient().create();
retrofit = new Retrofit.Builder().baseUrl(baseUrl).addConverterFactory(GsonConverterFactory.create(gson)).build();
}
return retrofit;
}
}
ApiInterface.java
public interface ApiInterface {
@FormUrlEncoded
@POST("local?")
Call<AuthResponse> loginm(@Field("email") String username, @Field("password") String password);
@GET("/orders?startDay=1&&startYear=2017&&startMonth=1&&endDay=1&&endYear=2018&&endMonth=1")
Call<OrderList> getOrder(@Header("Authorization") String authorization, @Header("language")String language);
}
ApiUtils.java
public class ApiUtils {
public static final String BASE_URL = "http://52.74.115.250:8080/";
static public String loginUrlStr = BASE_URL +"auth/";
static public String dealStr=BASE_URL+"api/";
public static ApiInterface getSOService(String url)
{
return RetrofitClient.getClient(url).create(ApiInterface.class);
}
}
This is how I am making request in MainActivity.java:
myInterface.getOrder(token,"english").enqueue(new Callback<OrderList>() {
@Override
public void onResponse(Call<OrderList> call, Response<OrderList> response) {
if(response.isSuccessful())
{
Log.d("resultorder","RESULT IS "+response.body().getOrders().size());
}
}
@Override
public void onFailure(Call<OrderList> call, Throwable t) {
}
});