2
I have a Core project where there is a User class
@XmlSeeAlso(value = {UserClient.class, UserProfessional.class})
public abstract class User implements Serializable {
Userprofessional class
@Getter
@XmlRootElement(name="professional")
@XmlAccessorType(XmlAccessType.FIELD)
public class UserProfessional extends User {
Userclient class
@XmlRootElement(name="client")
@XmlAccessorType(XmlAccessType.FIELD)
public class UserClient extends User {
When trying to make a callback using retrofit I get the following error
Exception in thread "main" java.lang.IllegalArgumentException: Unable to create converter for class servi.sale.core.shared.user.User for method UserService.auth at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:755) at retrofit2.ServiceMethod$Builder.createResponseConverter(ServiceMethod.java:741) at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:172) at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:170) at retrofit2.Retrofit$1.invoke(Retrofit.java:147) at com.sun.proxy.$Proxy0.auth(Unknown Source) at sale.servi.servisale.Playground.main(Playground.java:29) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Caused by: java.lang.Illegalargumentexception: Could not locate Responsebody converter for class servi.sale.core.shared.user.User. Tried: * retrofit2.Builtinconverters * retrofit2.converter.jaxb.Jaxbconverterfactory retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:351) retrofit2.Retrofit.responseBodyConverter(Retrofit.java:313) Servicemethod$Builder.createResponseConverter(Servicemethod.java:739) ... 10 more
Callback
UserAuth auth = new UserAuth("[email protected]", 1,"1234");
Main.getRetrofitFactory().getUserService().auth(auth).enqueue(new
Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response){
System.out.print(response.body());
}
@Override
public void onFailure(Call<User> call, Throwable t) {
System.out.print("deu ruim!!" + t.getMessage());
}
});
Retrofit boot
public class RetrofitFactory {
private final Retrofit retrofit;
public RetrofitFactory(){
retrofit = new Retrofit.Builder().baseUrl("myurl")
.addConverterFactory(JaxbConverterFactory.create()).build();
}