gwtp可以';t反序列化响应
我将carstore示例中的代码移植到我的原型应用程序中,遇到了一个奇怪的问题。我无法对json响应进行反序列化 错误如下:gwtp可以';t反序列化响应,gwt,gwt-platform,gwtp,Gwt,Gwt Platform,Gwtp,我将carstore示例中的代码移植到我的原型应用程序中,遇到了一个奇怪的问题。我无法对json响应进行反序列化 错误如下: com.gwtplatform.dispatch.shared.ActionException: Unable to deserialize response. at com.gwtplatform.dispatch.client.rest.RestResponseDeserializer.getDeserializedResponse(RestResponseD
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);
}
以及我的实体:
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);
}
public类Employee实现Dto{
公共int empno;
公共字符串名;
公共字符串lastName;
公共字符串扩展;
公共字符串电子邮件;
公共字符串;
公共int报告;
公开职位;
/**
*提供联系人唯一ID的密钥提供程序。
*/
公共静态最终ProvidesKey\u PROVIDER=新ProvidesKey(){
@凌驾
公共对象getKey(员工项){
return item==null?null:item.getEmpno();
}
};
/**
*如何为数据创建JSONECoder实例的示例
*转移对象。
*
*公共接口EmployeeJED扩展了JSONECoder{
*
* }
*
*@param empno
*@param firstName
*@param lastName
*@param扩展名
*@param电子邮件
*@param officeCode
*@param reportsTo
*@param jobTitle
*/
公职人员(
int empno,
字符串名,
字符串lastName,
字符串扩展名,
字符串电子邮件,
字符串代码,
int reportsTo,
字符串(职务名称){
这是setEmpno(empno);
这个.setFirstName(firstName);
此.setLastName(lastName);
这个.setExtension(extension);
这个.seteMail(eMail);
这个.setOfficeCode(officeCode);
此.setReportsTo(reportsTo);
此.setJobTitle(jobTitle);
}
公共雇员(int empno、String firstName、String lastName、int reportsTo){
这是setEmpno(empno);
这个.setFirstName(firstName);
此.setLastName(lastName);
此.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());
}
});
}
@覆盖
受保护的void onReveal(){
//ActionBarVisibilityEvent.fire(这是真的);
//ChangeActionBarEvent.fire(this,Arrays.asList(ActionType.ADD),true);
execute(employeeService.getEmployees(1),新的AbstractAsyncCallback(){
@凌驾
成功时公共无效(GetResults结果){
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示例中使用的模型。知道这为什么不起作用吗?看看这里,我发现您可能会使用RestAction Inst另外,com.gwtplatform.carstore.shared.dto中的dto都具有无参数构造函数(反序列化过程可能需要此构造函数)好吧,这是一个开始,问题是代码甚至还没有出现在快照中。我只是拉了代码并试图编译它,因为他们更改了RestAction对象,而rest项目已损坏,无法编译。而且我也没有参数构造函数。我只是没有将它们粘贴到这里。仅供参考:r中的api有很大变化est dispatcher很快就会出现,比你现在正在使用的实验性东西稳定得多:D Oh和SP是对的,可序列化对象必须总是有一个空的CTOR。是的,我在看你5天前合并的代码。看起来不错,我喜欢你做的,但是你在一些地方使用X作为返回,这h不会在JDK 6上编译。而且我受公司政策的约束,永远不会承认JDK 7已经发布。我想我会继续玩Resty GWT,因为这需要今天完成。
@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>