You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@Testpublicvoidtest() throwsIOException {
finalOkHttpClientclient = newOkHttpClient();
varretrofit = newRetrofit.Builder()
.addConverterFactory(JacksonConverterFactory.create())
.baseUrl("http://whatever/") //We fail before we hit this!
.client(client)
.build();
Serviceservice = retrofit.create(Service.class);
varcall = service.upload(newCar());
call.execute();
}
This gives the following error:
java.lang.IllegalArgumentException: Unable to convert SimpleRetrofitTest$Car@14bdbc74 to RequestBody (parameter #1)
for method Service.upload
at retrofit2.Utils.methodError(Utils.java:53)
...
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class SimpleRetrofitTest$Car and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
...
at retrofit2.converter.jackson.JacksonRequestBodyConverter.convert(JacksonRequestBodyConverter.java:34)
at retrofit2.converter.jackson.JacksonRequestBodyConverter.convert(JacksonRequestBodyConverter.java:24)
at retrofit2.ParameterHandler$Body.apply(ParameterHandler.java:411)
... 70 more
It's struggling to serialize from the interface to the class. The code works fine if I change the API to: public Call<String> upload(@Body Car vehicle);, so a Car can definitely be serialised. But the JacksonConverter seems to struggle with the polymorphism in this instance.
I'm trying to get Retrofit to work with polymorphic types, something like this:
Here's my service:
And here's my test:
This gives the following error:
It's struggling to serialize from the interface to the class. The code works fine if I change the API to:
public Call<String> upload(@Body Car vehicle);
, so aCar
can definitely be serialised. But the JacksonConverter seems to struggle with the polymorphism in this instance.I've got a complete Gist for this test here: https://gist.github.com/msmerc/4a53b51200bd1e80ce1e9f7ffe3efb16
The text was updated successfully, but these errors were encountered: