Lorsque vous essayez de POST
certaines données JSON en utilisant Retrofit 2.0.0-beta4
, je reçois l'erreur suivante:ne pouvez pas poster JSON avec Retrofit 2
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)
...
Je ne sais pas ce qui se passe ici. Pour autant que je sache, ma configuration suit textuellement d'autres exemples fonctionnant vraisemblablement.
Mon application niveau 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'
...
}
Et mon constructeur de rénovation:
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();
Toutes les idées que je fais mal?
Modifier
Mon interface API ressemble à ceci:
import retrofit2.Call;
import retrofit2.http.*;
public interface MyRestApi {
@POST("/auth")
Call<Auth> login(@Body Credentials user);
}
Et l'appel 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) {
...
}
});