Search code examples
google-app-enginerestgwtresty-gwt

RestyGWT Must be annotated with JsonTypeInfo


I'm trying to get data via my Restservice. Therefor I'm Having my spring controller and my rest service.

@Path("/user")
public interface UserAdminRestService extends RestService {
    public static class Util {

        private static UserAdminRestService instance;

        /**
         * Returns an instance of the {@link UserAdminRestService}.
         * @return an instance of the UserAdminRestService.
         */
        public static UserAdminRestService getUserAdminRestService() {

            Resource resource = new Resource(GWT.getModuleBaseURL() + "user");
            GWT.log("UserAdmin-Rescource-Path: "+resource.getPath());
            if (instance == null ) {
                instance = GWT.create(UserAdminRestService.class);
            }

            ((RestServiceProxy) instance).setResource(resource);

            return instance;


        }
    }

    @GET
    @PATH("/test")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public void getUsers(MethodCallback<List<GWTUser>> callback);

}

The GWTUser represent my User entity.

public class GWTUser {

    public interface GWTUserJED extends JsonEncoderDecoder<GWTUser> {

    }

    private String userId;

    ... // data

    @Override
    public String toString() {
        if (GWT.isClient()) {
            GWTUserJED jed = GWT.create(GWTUserJED.class);
            return jed.encode(this).toString();
        }
        return super.toString();
    }
}

And I'm trying to call it in my gwt application:

HashMap<String, String> header = new HashMap<String, String>();
header.put(Resource.HEADER_ACCEPT, Resource.CONTENT_TYPE_JSON+"; charset=utf-8");

Resource resourceGetUsers = new Resource("/user/test", header);

UserAdminRestService.Util.getUserAdminRestService().getUsers(new MethodCallback<List<GWTUser>>() {

    @Override
    public void onFailure(Method method, Throwable exception) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onSuccess(Method method, List<GWTUser> response) {
        // TODO Auto-generated method stub

    }

});

But I'm getting an error message when I'm trying to compile my application.

 --- gwt-maven-plugin:2.5.1:compile (default-cli) @ myapp-admin-gwt ---
 auto discovered modules [com.myapp.admin.gwt]
 Compiling module com.myapp.admin.gwt
    Computing all possible rebind results for 'com.myapp.admin.rest.UserAdminRestService'
       Rebinding com.myapp.admin.rest.UserAdminRestService
          Invoking generator org.fusesource.restygwt.rebind.RestServiceGenerator
             Generating: com.myapp.admin.rest.UserAdminRestService_Generated_RestServiceProxy_
                Generating: com.google.gwt.http.client.Response_Generated_JsonEncoderDecoder_
                   [ERROR] Abstract classes must be annotated with JsonTypeInfo
    [ERROR] Errors in 'com/myapp/admin/rest/UserAdminRestService.java'
       [ERROR] Line 53: Failed to resolve 'com.myapp.admin.rest.UserAdminRestService' via deferred binding
    [WARN] For the following type(s), generated source was never committed (did you forget to call commit()?)
       [WARN] com.myapp.admin.rest.UserAdminRestService_Generated_RestServiceProxy_
       [WARN] com.google.gwt.http.client.Response_Generated_JsonEncoderDecoder_

So I'm not sure what to do. Do I need an JsonTypeInfo for my Service, but what for?! Or do I need to make my GWTUser abstract and add a JsonTypeInfo. Thanks for any help.


Solution

  • Not sure but might be linked to the fact that your GWTUser has an interface inside that RestyGWT cannot resole.

    Try moving out your JsonEncoderDecoder outside your User class.