RestyGWT必须使用JsonTypeInfo进行注释

时间:2014-03-25 15:44:18

标签: google-app-engine rest gwt resty-gwt

我正试图通过我的Restservice获取数据。因此,我有我的弹簧控制器和我的休息服务。

@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);

}

GWTUser代表我的用户实体。

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();
    }
}

我试图在我的gwt应用程序中调用它:

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

    }

});

但是当我尝试编译应用程序时,我收到一条错误消息。

 --- 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_

所以我不知道该怎么做。我的服务需要JsonTypeInfo吗?但是对于什么?!或者我是否需要创建GWTUser摘要并添加JsonTypeInfo。谢谢你的帮助。

1 个答案:

答案 0 :(得分:2)

不确定但可能与您的GWTUser内部具有RestyGWT无法解析的接口这一事实有关。

尝试在User类之外移出JsonEncoderDecoder。