При попытке POST
некоторых данных JSON с помощью Retrofit 2.0.0-beta4
я получаю следующую ошибку:
java.lang.IllegalArgumentException: Unable to create @Body converter for class my.pojos.Credentials
...
Caused by: java.lang.IllegalArgumentException: Could not locate RequestBody converter for class my.pojos.Credentials.
Tried:
* retrofit2.BuiltInConverters
* retrofit2.GsonConverterFactory
at retrofit2.Retrofit.nextRequestBodyConverter(Retrofit.java:288)
...
Не знаю, что здесь происходит. Насколько я знаю, моя установка дословно следует другим предположительно рабочим примерам.
Мой уровень приложения build.gradle
:
dependencies {
...
compile 'com.google.code.gson:gson:2.5'
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
compile 'com.squareup.okhttp:okhttp:2.7.0'
...
}
И мой ремонтный конструктор:
Gson gson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(context.getString(R.string.rest_url))
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
Любые идеи, что я делаю неправильно?
Изменить
Мой интерфейс API выглядит так:
import retrofit2.Call;
import retrofit2.http.*;
public interface MyRestApi {
@POST("/auth")
Call<Auth> login(@Body Credentials user);
}
И вызов API:
Call<Auth> authCall = retrofit.create(MyRestApi.class).login(creds);
authCall.enqueue(new Callback<Auth>() {
@Override
public void onResponse(Call<Auth> call, Response<Auth> response) {
...
}
@Override
public void onFailure(Call<Auth> call, Throwable t) {
...
}
});