我开发了多个 GWT Web 应用程序。最新的一个是对另一个的稍微修改。除了最新的之外,所有这些都运行良好。异常(exception)是:
The response could not be deserialized
我正在使用 Hibernate 以及 Hibernate 和 GWT 之间的数据传输对象。每个 DTO 都实现 java.io.Serializable 接口(interface)。正如我之前所说,在其他应用程序中效果很好。有人可以帮我解决这个错误吗?不知道是什么原因。
我的 Hibernate 对象代码是:
public List<AttributeDTO> getAttributes(){
String sql = "from Attribute where (select max(tDate) from Attribute)-tDate < '0 days 00:05'";
List<Attribute> attributes = new ArrayList<Attribute>(DatabaseManager.createQuery(sql));
List<AttributeDTO> attributeDTOs = new ArrayList<AttributeDTO>(attributes != null ? attributes.size() : 0);
if (attributes != null) {
for (Attribute attribute : attributes) {
String date = format.format(attribute.gettDate());
attributeDTOs.add(new AttributeDTO(attribute.getiAttrId(),attribute.getsName(),attribute.getsValue(),date,attribute.getiDeviceId(),attribute.getsUnits(),new ApplicationFieldDTO()));
}
}
return attributeDTOs;
}
AttributeDTO 是:
public class AttributeDTO implements Serializable {
private static final long serialVersionUID = 1L;
private int iAttrId;
private String name;
private String value;
private String date;
private String units;
private int iDeviceId;
private ApplicationFieldDTO appField;
public AttributeDTO() {}
public AttributeDTO(int attrId, String name, String value, String date, int deviceId, String units, ApplicationFieldDTO appField) {
this.iAttrId = attrId;
this.name = name;
this.value = value;
this.date = date;
this.iDeviceId = deviceId;
this.units = units;
this.appField = appField;
}
}
从 GWT 调用 getAttributes() 方法,该方法返回 AttributeDTO 列表。
谢谢!!!
最佳答案
如果类中只有一个成员不可序列化,也会出现该错误 - 因此该错误也可能出现在 ApplicationFieldDTO 的定义中。
顺便说一下,除了使用数据传输对象,您还可以使用 Gilead ,那么即使延迟加载也可以工作。 (但就您现有的应用程序而言,引入吉利德可能需要大量工作。)
关于java - GWT错误: The response could not be deserialized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10100619/