自定义ArrayList序列化
我试图序列化一个包含自定义对象的 ArrayList 。
我在 Servlet
(服务器端)中对其进行序列化,并在客户端进行反序列化。 (使用ObjectOutputStream
和ObjectInputStream
)
当我使用ArrayList
时,它工作得很好。
但是当我用 ArrayList
尝试时,我无法在客户端得到任何结果,这是例外:
java.lang.ClassNotFoundException: web.MyObject
当然我已经这样做了:
public class MyObject implements Serializable { ... }
MyObject
contains仅String
字段。
我做错了什么?
谢谢,
射线。
I was trying to serialize an ArrayList
which contains custom objects.
I'm serializing it in a Servlet
(server side), and deserialize at the client side. (using ObjectOutputStream
and ObjectInputStream
)
It worked fine, when I work with ArrayList<String>
.
But when I tried it with ArrayList<MyObject>
I couldn't get any results in the client side, this is the exception:
java.lang.ClassNotFoundException: web.MyObject
Of course I have done this:
public class MyObject implements Serializable { ... }
MyObject
contains only String
fields.
What have I done wrong?
Thanks,
Ray.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您的客户端在反序列化时不知道您的 MyObject。所以你必须确保这个类也在类路径中。
编辑:哦,天哪,我刚刚看到安东更快
The Problem is that your client doesnt know your MyObject when Deserialization. So you have to make sure that this class in also on the classpath.
Edit: oh sry i just saw that Anton was faster