I'm new in Android development. This is my MainActivity.java. I already set the lenient and still receiving error D/onFailure: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $
API returns: Its either Success
or Validation like Error: FirstName is invalid.
private void saveUser() {
showpDialog();
Gson gson = new GsonBuilder().setLenient().create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("BASE_URL")
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
APIService service = retrofit.create(APIService.class);
User user = new User();
user.setFirstName(editName.getText().toString());
Call<User> call = service.saveUser(user.getFirstName());
call.enqueue(new Callback<User>() {
@Override
public void onResponse(Response<User> response) {
hidepDialog();
Log.d("onResponse", "" + response.code() +
" response body " + response.body() +
" responseError " + response.errorBody() + " responseMessage " +
response.message());
}
@Override
public void onFailure(Throwable t) {
hidepDialog();
Log.d("onFailure", t.toString());
}
});
}
Ive been searching and all of them says i need to setLenient to true, but I already did that. Any idea?