non serializable session websocket java ee

醉酒当歌 提交于 2019-12-23 02:26:44

问题


I write a ExchangeMoney class implements Serializable interface . This class has Session (javax.websocket.Session) property. 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.


回答1:


Check this post. Java Serialization with non serializable parts

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.




回答2:


Reconsider the design. Why does a serializable object requires a websocket session inside it and if it is required, shouldn't it be transient?



来源:https://stackoverflow.com/questions/28415902/non-serializable-session-websocket-java-ee

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!