Failed to create converter for java.util.List Retrofit 2.0.0-beta2

I just make a GET request, but I get this error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.yomac_000.chargingpoint/com.example.yomac_000.chargingpoint.AllStores}: java.lang.IllegalArgumentException: Unable to create converter for java.util.List<model.Store> 

And this is because of this line of code:

 Call<List<Store>> call = subpriseAPI.listStores(response); 

So, I tried with this line of code to see what type it is:

 System.out.println(subpriseAPI.listStores(response).getClass().toString()); 

But then I get the same error, so it does not let me know what type it is. Below you can see my code.

StoreService.java:

 public class StoreService { public static final String BASE_URL = "http://getairport.com/subprise/"; Retrofit retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) .build(); SubpriseAPI subpriseAPI = retrofit.create(SubpriseAPI.class); String response = ""; public List<Store> getSubprises() { Call<List<Store>> call = subpriseAPI.listStores(response); try { List<Store> listStores = call.execute().body(); System.out.println("liststore "+ listStores.iterator().next()); return listStores; } catch (IOException e) { // handle errors } return null; } } 

SubpriseAPI.java:

 public interface SubpriseAPI { @GET("api/locations/get") Call<List<Store>> listStores(@Path("store") String store); } 

Store.java:

 public class Store { String name; } 

I am using Retrofit version 2.0.0-beta2.

+7
java android retrofit
source share
2 answers

In version 2+ you need to tell the converter

NEUTRALIZERS

By default, Retrofit can only deserialize HTTP bodies into OkHttp's ResponseBody type, and it can only accept its RequestBody type for @body.

Converters can be added to support other types. Six native modules adapt popular serialization libraries for your convenience.

Gson: com.squareup.retrofit: converter-gson Jackson: com.squareup.retrofit: converter-jackson Moshi: com.squareup.retrofit: converter-moshi Protobuf: com.squareup.retrofit: converter-protobuf Wire: com.squareup. retrofit: Simple XML wire converter: com.squareup.retrofit: SimpleXML converter

  //Square Lib, Consume Rest API compile 'com.squareup.retrofit:retrofit:2.0.0-beta1' compile 'com.squareup.okhttp:okhttp:2.4.0' compile 'com.squareup.retrofit:converter-gson:2.0.0-beta1' 

So,

  String baseUrl = "" ; Retrofit client = new Retrofit.Builder() .baseUrl(baseUrl) .addConverterFactory(GsonConverterFactory.create()) .build(); 
+18
source share
 public interface SubpriseAPI { @GET("api/locations/get") Call<List<Store>> listStores(@Path("store") String store); } 

you declared a repository named @Path , so it’s expected in your @GET annotation that it will find a placeholder for replacement. For example.

 @GET("api/locations/{store}") Call<List<Store>> listStores(@Path("store") String store); 
+3
source share

All Articles