Retrofit is not returning full String

Viewed 329

I am facing this problem for many hours. I have a string 123#5432#7 on this link, but when I try to fetch this through Retrofit, I only get characters before first #, in this case, the output is 123 but I want the whole string. I tried to fetch it with OkHttpClient, it's working fine. Can anyone find the problem with my code Or What other possible ways?

Output

123

but I want whole string like 123#5432#7

Edit: added .addConverterFactory(ScalarsConverterFactory.create()) but yet same response.

Code

public class ApiClient {
    public static Retrofit retrofit;
    public static String BASE_URL = "https://prdec.com/status_app/";


    public static Retrofit getRetrofit(){
        Gson gson = new GsonBuilder()
                .setLenient()
                .create();
        if (retrofit == null){
            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create(gson))
                    .addConverterFactory(ScalarsConverterFactory.create())
                    .build();
        }
        return retrofit;
    }
}


public interface ApiService {

    @GET("status_app_return_string.php")
    Call<String> getStringResponse();
}


                ApiService apiService = ApiClient.getRetrofit().create(ApiService.class);
                apiService.getStringResponse()
                        .enqueue(new Callback<String>() {
                            @Override
                            public void onResponse(Call<String> call, Response<String> response) {
                                String str = response.body();
                                Log.d(TAG, "onResponse: "+str);
                            }

                            @Override
                            public void onFailure(Call<String> call, Throwable t) {


                            }
                        });

1 Answers

The problem was with the ranking of .addConverterFactory(GsonConverterFactory.create(gson)) and addConverterFactory(ScalarsConverterFactory.create())

ScalarsConverterFactory should be above other converters factories.

Not working

 retrofit = new Retrofit.Builder()
      .baseUrl(BASE_URL)
      .addConverterFactory(GsonConverterFactory.create(gson))
      .addConverterFactory(ScalarsConverterFactory.create())
      .build();

Working

 retrofit = new Retrofit.Builder()
       .baseUrl(BASE_URL)
       .addConverterFactory(ScalarsConverterFactory.create())
       .addConverterFactory(GsonConverterFactory.create(gson))
       .build();
Related