By looking into your comments I assume that your POJO class is proper but the way you're using it with Retrofit call is wrong. Make sure that the POJO class is like below,
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Foo {
@SerializedName("positive")
@Expose
private List<String> positive = null;
@SerializedName("medical")
@Expose
private List<String> medical = null;
public List<String> getPositive() {
return positive;
}
public List<String> getMedical() {
return medical;
}
}
And use above POJO class like this.
Your API interface
import retrofit2.Call;
import retrofit2.http.GET;
public interface FooApiInterface {
/* pass POJO class to Call<> */
@GET("request/url")
Call<Foo> getFoo(/* parameters for the request if there any */);
/* other api calls here */
}
Next use API interface
FooApiInterface client = ...; // initialization
Call<Foo> fooCall = client.getFoo();
fooCall.enqueue(
new Callback<Foo>() {
@Override
public void onResponse(@NonNull Call<Foo> call, @NonNull Response<Foo> response) {
if (response.isSuccessful()) {
List<String> positiveList = response.body().getPositive();
List<String> medicalList = response.body().getMedical();
}
}
@Override
public void onFailure(@NonNull Call<Foo> call, @NonNull Throwable t) {
Log.e("error", "API Error ", t);
}
}
);
Notice that, here I am using Foo
POJO class as parameter to Call
instead of List<Strain>
(like used in your code). If you modify the code as said above, you can get rid of the error
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $ error
For demonstration purpose I used Foo
example. Change it according to your requirements.
> call, Response
– Sivan Oct 16 '18 at 16:11> response) { List basicDetailsList2 = response.body();
List positiveTraitsArray = basicDetailsList2.get(checknum).getPositive();
Log.d("Positive array", "onResponse: " + positiveTraitsArray);
}
@Override
public void onFailure(Call
> call, Throwable t) { Log.d("Error strainCall2 : ", "onFailure: " + t); } });`