Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit 2 : End of input at line 1 column 1 path $

Have made a thorough searching to this particular problem but while implementing answers under each question I encountered, am still getting the same output:

 End of input at line 1 column 1 path $ 

I perfomed my Request on PostMan and I got expected output: Here is the Screenshot of the Postman Request

Interfaces

 @POST(Constant.API_REQUEST)
    Observable<ServerResponse> postToWinnersList(@Body ServerRequest serverRequest);

ApiClient

public class ApiClient {
    public static Retrofit retrofit;

    private static OkHttpClient.Builder okHttpClientBuilder;
    private static HttpLoggingInterceptor loggingInterceptor;


    public static Retrofit getApiClient(){
        if (retrofit == null){
//            create instance of Httpclient
            okHttpClientBuilder = new OkHttpClient.Builder();
            loggingInterceptor = new HttpLoggingInterceptor();
            loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

            if(BuildConfig.DEBUG){
                okHttpClientBuilder.addInterceptor(loggingInterceptor);
            }
//            instance of retrofit
            retrofit = new Retrofit.Builder().baseUrl(Constant.BASE_URL).
                    addCallAdapterFactory(RxJava2CallAdapterFactory.create()).
                    addConverterFactory(GsonConverterFactory.create())
                    .client(okHttpClientBuilder.build())
                    .build();
        }
        return retrofit;
    }
}

Retrofit/RxJava Request Code:

     Observable<ServerResponse> response = apiInterface.postToWinnersList(serverRequest);
                response.observeOn(AndroidSchedulers.mainThread())
                        .subscribeOn(Schedulers.io())
                        .subscribeWith(new DisposableObserver<ServerResponse>() {
                            @Override
                            public void onNext(ServerResponse serverResponse) {
                                AVLoadingIndicatorView1.setVisibility(View.GONE);
                                txtSubmitWinner.setVisibility(View.VISIBLE);
                            }

                            @Override
                            public void onError(Throwable e) {
                                AVLoadingIndicatorView1.setVisibility(View.GONE);
                                txtSubmitWinner.setVisibility(View.VISIBLE);
                                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
                            }

                            @Override
                            public void onComplete() {
                                showShortMsg(getString(R.string.submit_success));
                            }
                        });

Kindly help, thanks in Advance.

like image 757
Raji Rajah Avatar asked Oct 19 '25 13:10

Raji Rajah


1 Answers

You can get this error when you are expecting an object in the response, but the API doesn't return anything other than result codes (200,...). Options: - Check that the API really returns a ServerResponse. - If you don't really need it to return anything, use Observable<Response<Void>> instead of Observable<ServerResponse>

like image 172
Pedro Gonzalez Avatar answered Oct 22 '25 04:10

Pedro Gonzalez