1
When I try to send an Arraylist via @POST to be saved to my webserver with Retrofit2, Arraylist is saved, but 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 fix this mistake? I think it has something to do with Gson, but I’m a beginner and I’m a little 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 runs the upload:
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);}