gwtp无法反序列化响应

时间:2013-12-03 14:21:34

标签: gwt gwt-platform gwtp

我将来自carstore示例的代码移植到我的原型应用程序中并遇到一个奇怪的问题。我无法得到反序列化json响应的东西。

继承错误:

com.gwtplatform.dispatch.shared.ActionException: Unable to deserialize response.
    at com.gwtplatform.dispatch.client.rest.RestResponseDeserializer.getDeserializedResponse(RestResponseDeserializer.java:60)
    at com.gwtplatform.dispatch.client.rest.RestResponseDeserializer.deserialize(RestResponseDeserializer.java:38)
    at com.gwtplatform.dispatch.client.rest.RestDispatchAsync$1.onResponseReceived(RestDispatchAsync.java:124)
    at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:258)
    at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:412)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
    at sun.reflect.GeneratedMethodAccessor246.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
    at java.lang.Thread.run(Unknown Source)
Caused by: com.google.gwt.user.client.rpc.SerializationException: com.google.gwt.json.client.JSONException: "[{"empno":0,"firstName":"Edith","lastName":"Fisher","reportsTo":0}]" represents invalid json data!
    at com.gwtplatform.dispatch.client.rest.JsonSerializer.deserialize(JsonSerializer.java:40)
    at com.gwtplatform.dispatch.client.rest.RestResponseDeserializer.getDeserializedResponse(RestResponseDeserializer.java:58)
    ... 29 more
Caused by: com.google.gwt.json.client.JSONException: "[{"empno":0,"firstName":"Edith","lastName":"Fisher","reportsTo":0}]" represents invalid json data!
    at name.pehl.piriti.json.client.AbstractJsonReader.read(AbstractJsonReader.java:226)
    at com.gwtplatform.dispatch.client.rest.JsonSerializer.deserialize(JsonSerializer.java:37)
    ... 30 more

我的服务界面:

@Path(ResourcesPath.JACKSON)
public interface EmployeeService extends RestService {
    /**
     * calls the get employees service.
     * 
     * @param num
     * @return GetResults<Employee>
     */
    @GET
    Action<GetResults<Employee>> getEmployees(@QueryParam("num") Integer num);
}

GetResults类:

public class GetResults<T extends Dto> implements Result {
    ArrayList<T> results;

    @SuppressWarnings("unused")
    protected GetResults() {
    }

    public GetResults(ArrayList<T> results) {
        this.results = results;
    }

    public ArrayList<T> getResults() {
        return results;
    }
}

Dto课程:

public interface Dto extends IsSerializable {
}

和我的实体:

public class Employee implements Dto {

    public int empno;
    public String firstName;
    public String lastName;
    public String extension;
    public String eMail;
    public String officeCode;
    public int reportsTo;
    public String jobTitle;

    /**
     * The key provider that provides the unique ID of a contact.
     */
    public static final ProvidesKey<Employee> KEY_PROVIDER = new ProvidesKey<Employee>() {
        @Override
        public Object getKey(Employee item) {
            return item == null ? null : item.getEmpno();
        }
    };

    /**
     * Example of how to create an instance of a JsonEncoderDecoder for a data
     * transfer object.
     * 
     * public interface EmployeeJED extends JsonEncoderDecoder<Employee> {
     * 
     * }
     * 
     * @param empno
     * @param firstName
     * @param lastName
     * @param extension
     * @param eMail
     * @param officeCode
     * @param reportsTo
     * @param jobTitle
     */
    public Employee(
            int empno,
            String firstName,
            String lastName,
            String extension,
            String eMail,
            String officeCode,
            int reportsTo,
            String jobTitle) {
        this.setEmpno(empno);
        this.setFirstName(firstName);
        this.setLastName(lastName);
        this.setExtension(extension);
        this.seteMail(eMail);
        this.setOfficeCode(officeCode);
        this.setReportsTo(reportsTo);
        this.setJobTitle(jobTitle);
    }

    public Employee(int empno, String firstName, String lastName, int reportsTo) {
        this.setEmpno(empno);
        this.setFirstName(firstName);
        this.setLastName(lastName);
        this.setReportsTo(reportsTo);
    }

并且好的方法是来自演示者的来电者

@Override
    protected void onReveal() {
        // ActionBarVisibilityEvent.fire(this, true);
        // ChangeActionBarEvent.fire(this, Arrays.asList(ActionType.ADD), true);

        dispatcher.execute(employeeService.getEmployees(1), new AbstractAsyncCallback<GetResults<Employee>>() {
            @Override
            public void onSuccess(GetResults<Employee> result) {
                getView().displaySearchGrid(result.getResults());
            }
        });

    }

和我的模块文件:

<module rename-to='gwtptabsample'>
    <!-- Inherit rest dispatch stuff. Order matters here, rest needs to be before mvp -->
    <inherits name="com.gwtplatform.dispatch.DispatchRest" />
    <inherits name="com.gwtplatform.mvp.MvpWithEntryPoint" />

    <!-- GinUiBinder allows injecting widgets in UiBinder -->
    <inherits name="com.google.gwt.uibinder.GinUiBinder" />

    <!-- debugging
    <inherits name="com.google.gwt.logging.Logging"/>
    <inherits name="com.google.gwt.user.Debug"/>
    <set-property name="gwt.logging.logLevel" value=INFO/>
    <set-property name="gwt.logging.enabled" value="TRUE"/> -->

    <!-- Inherit the default GWT style sheet. You can change -->
    <!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
    <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
    <inherits name="com.google.gwt.user.theme.dark.Dark" />



    <!-- Specify the paths for translatable code -->
    <source path="client" />
    <source path="shared"/>

    <extend-configuration-property name="gin.ginjector.modules"
        value="com.gwtplatform.samples.tab.client.gin.ClientModule" />

    <set-configuration-property name="gin.ginjector.extensions"
        value="com.gwtplatform.samples.tab.client.gin.GinjectorExtension" />
</module>

参数中的数字只是告诉我的服务要生成多少随机员工。如果我调用一个或多个结果,我会得到相同的错误。同样,这是基于GWTP源树中CarStore示例中使用的模型。任何想法为什么这不起作用?

0 个答案:

没有答案