【问题标题】:GWT error: The response could not be deserializedGWT 错误:无法反序列化响应
【发布时间】:2012-04-11 05:56:20
【问题描述】:

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

The response could not be deserialized

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

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

谢谢!!!

【问题讨论】:

  • 您应该发布给您带来麻烦的 DTO 代码

标签: java hibernate gwt dto


【解决方案1】:

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

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

【讨论】:

  • 谢谢,看起来很有趣。我会研究这种可能性
【解决方案2】:

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

【讨论】:

  • 在第一次开发时我有 com.google.gwt.user.client.rpc.IsSerializable ,后来我改变了 java.io.Serializable 因为它不起作用。我认为这不是问题,但感谢您的回复
  • @JoseHdez 您能否将异常堆栈跟踪附加到问题中?
【解决方案3】:

使用 ArrayList 代替 List 并重试

看看这个post

【讨论】:

  • new ApplicationFieldDTO() 也许是这个?这个类是序列化的还是有一个空的构造函数,不使用像 List 这样的泛型类型???
  • ApplicationDTO 是另一个 DTO 类,代码为: public class ApplicationFieldDTO implements Serializable{ public ApplicationFieldDTO(){} }
  • 看这个看这个[帖子][1][1]:stackoverflow.com/questions/5553593/…
【解决方案4】:

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

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

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

后来我在 eclipse 中安装了一个插件,它对我来说很好用。我使用这个link

从 Eclipse Marketplace 安装了插件

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-14
  • 2012-08-01
  • 2020-08-15
  • 1970-01-01
相关资源
最近更新 更多