简体   繁体   English

不可序列化的会话websocket java ee

[英]non serializable session websocket java ee

I write a ExchangeMoney class implements Serializable interface . 我写了一个ExchangeMoney类实现Serializable接口。 This class has Session (javax.websocket.Session) property. 此类具有Session(javax.websocket.Session)属性。 See code below: 参见下面的代码:

import javax.websocket.Session;
import javax.websocket.EncodeException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.Serializable;
...
public class ExchangeMoney implements Serializable {

    private static final long serialVersionUID = -4363184570862565571L;

    private static final Logger logger = Logger.getLogger("ExchangeMoney ");

    private Session session;

    ....
}

Error due to session field non serializable. 由于会话字段不可序列化而导致的错误。 How to resolve this problem. 如何解决这个问题。

Check this post. 检查这篇文章。 Java Serialization with non serializable parts 具有不可序列化部分的Java序列化

Basically you can extend session and implement serializable and override writeObject and readObject methods and try to persist and read the values you are interested in. 基本上,您可以扩展会话并实现可序列化并覆盖writeObject和readObject方法,并尝试保留并读取您感兴趣的值。

Reconsider the design. 重新考虑设计。 Why does a serializable object requires a websocket session inside it and if it is required, shouldn't it be transient? 为什么可序列化的对象内部需要一个websocket会话,如果需要,不是瞬态的吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM