When I try to send an ArrayList via @POST to be saved in my webserver with Retrofit2, the ArrayList is saved, however I am getting the following error:
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
What can I do to resolve this error? I think it has something to do with Gson, but I'm a beginner and I'm kind of lost.
This is the ArrayList I'm trying to send:
ArrayList<ModelContato> listContatos = new ArrayList<>();
ModelContato c = new ModelContato("5", "ATIVO", "TESTE", "12134567", "14646", "[email protected]", "Teste");
listContatos.add(c);
c = new ModelContato("6", "INATIVO", "TESTE2", "12123456", "14646", "[email protected]", "Teste2");
listContatos.add(c);
And this is my Call that makes sending:
Call<List<ModelContato>> callM = contatoInterface.createRContato(listContatos);
callM.enqueue(new Callback<List<ModelContato>>() {
@Override
public void onResponse(Response<List<ModelContato>> response, Retrofit retrofit) {
Log.i("TAG", "Salvo com sucesso");
}
@Override
public void onFailure(Throwable t) {
Log.i("TAG", "Erro ao salvar: " + t.getMessage());
}
});
This is my interface:
public interface ContatoInterface {
@GET("recebe")
Call<List<ModelContato>> getRContatos();
@POST("envia")
Call<List<ModelContato>> createRContato(@Body ArrayList<ModelContato> modelContato);}