JaxB Converting Abstract Class with Retrofit

2

I have a Core project where the User class exists

@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       at retrofit2.Retrofit.nextResponseBodyConverter (Retrofit.java:351)       at retrofit2.Retrofit.responseBodyConverter (Retrofit.java:313)       at retrofit2.ServiceMethod $ Builder.createResponseConverter (ServiceMethod.java:739)       ... 10 more

Callback code

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 initialization

public class RetrofitFactory {

private final Retrofit retrofit;

public RetrofitFactory(){
    retrofit = new Retrofit.Builder().baseUrl("myurl")
            .addConverterFactory(JaxbConverterFactory.create()).build();
}
    
asked by anonymous 19.10.2018 / 06:33

0 answers