0

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.

vicR
  • 789
  • 4
  • 23
  • 52
  • Some comments on your code : as you are using the @Path annotation you do not need the `setResource`. If you have a problem setting the first part of your path you can use `Defaults.setServiceRoot( baseUrl)` where baseUrl can be `GWT.getHostPageBaseURL()` or `GWT.getModuleBaseURL()` as you do already. I would not instantiate the client inside the interface also for readibility reasons. Why are you using a JsonEncoderDecoder ? Why dont you use a simple Pojo with getters and setters ? Here you are making your User object depends on GWT lib. – Ronan Quillevere Mar 25 '14 at 17:26
  • I'm trying to do the deoding/encoding like in the documenation http://restygwt.fusesource.org/documentation/restygwt-user-guide.html – vicR Mar 26 '14 at 07:25
  • If you want a simple example you can have a look here http://ronanquillevere.github.io/2014/03/16/gwt-rest-app.html – Ronan Quillevere Mar 26 '14 at 08:17

1 Answers1

2

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.

Ronan Quillevere
  • 3,699
  • 1
  • 29
  • 44
  • fixed my problem. yeah the JsonEncoderDecoder was not necessary, everything is done by restygwt :) thx for your help. – vicR Mar 26 '14 at 13:13