0

我已经开发了几个 GWT Web 应用程序。最新的一个是对另一个的小修改。除了最新的,它们都运行良好。例外是:

The response could not be deserialized

我在 Hibernate 和 GWT 之间使用 Hibernate 和数据传输对象。每个 DTO 都实现 java.io.Serializable 接口。正如我之前所说,在其他应用程序中运行良好。有人可以帮我解决这个错误吗?我不知道是什么原因。

我的休眠对象代码是:

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 列表。

谢谢!!!

4

4 回答 4

1

如果您的类中只有一个成员不可序列化,也会出现该错误 - 因此该错误也可能在 ApplicationFieldDTO 的定义中。

顺便说一句,您也可以使用Gilead ,而不是使用数据传输对象,然后甚至延迟加载也可以工作。(但对于您现有的应用程序,引入 Gilead 可能需要做很多工作。)

于 2012-04-11T11:57:09.580 回答
0

使用ArrayList而不是 List 并重试

看看这个帖子

于 2012-04-11T06:14:25.423 回答
0

我有同样的麻烦。尝试使用 com.google.gwt.user.client.rpc.IsSerializable 而不是 Serializable。它对我有用,我希望对你有帮助:)

于 2012-04-11T06:28:04.297 回答
0

我也遇到了类似的问题。在我从 UI 提交值的情况下,异常

“GWT 错误:无法反序列化响应”

显示。我发现整个代码库没有正确打包以转换为 .war 文件。我正在使用 Ant Build 方法来创建.war文件。

后来我在eclipse中安装了一个插件,对我来说效果很好。我使用此链接从 eclipse 市场安装了插件

于 2018-09-10T07:41:37.093 回答