0

I am trying to send Json with formated Date (pattern="yyyy-MM-dd HH:mm:ss").The problem is that server don't recognize this pattern and give error java.io.EOFException: \n not found: limit=1 content=0d… I tried add GsonBuilder in RetrofitClient class, but it doesn't worked.

String mobileDate= (String) android.text.format.DateFormat.format("yyyy-MM-dd HH:mm:ss", new java.util.Date());

RetrofitClient

public class RetrofitClient {

    private static Retrofit retrofit=null;
    private static  String base_url= null;

    public static void setBaseUrl(String string){
         base_url = string;
    }
    public  static  void deletePreviousInstance(){
        retrofit=null;
    }

    public static Retrofit getRetrofitInstance(){

        if(retrofit==null){


             Gson gson = new GsonBuilder()
                .setDateFormat("yyyy-MM-dd HH:mm:ss")
                .create();
        OkHttpClient okHttpClient = new OkHttpClient().newBuilder()
                .connectTimeout(25, TimeUnit.SECONDS)
                .readTimeout(25, TimeUnit.SECONDS)
                .writeTimeout(25, TimeUnit.SECONDS)
                .build();
        retrofit= new Retrofit.Builder()
                .baseUrl(base_url)
                .client(okHttpClient)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build();
        }
        return retrofit;
    }

}



    
okirP
  • 13
  • 2

1 Answers1

1

you are giving a string as parameter for date format you have to parse the same date format at the server end. you can check out this link https://stackoverflow.com/a/882465/2285117