I am getting this error when I try to add data to a database with retrofit and I don't know why.
Error:
Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $
Service:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://invazoras-g5-back-desa.herokuapp.com/")
.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(ScalarsConverterFactory.create())
.build();
final HerokuService service = retrofit.create(HerokuService.class);
Call:
User user = new User (name, email, password, habilitated, moderator);
Call<User > call = service.create(user);
call.enqueue(new Callback<User >() {
@Override
public void onResponse(Call<User > call, Response<User > response) {
User newUser= response.body();
Toast.makeText(getApplicationContext(), "User"+newUser +"created", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Call<User > call, Throwable t) {
t.printStackTrace();
Toast.makeText(getApplicationContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
Any help would be appreciated.
If you recieving this error when building your project - check google-services.json file. In my case it contained a comment left from previous developer which caused the error.
Try using .setLenient() if you have a GsonBuilder somewhere. This post might help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With