简体   繁体   English

检测何时序列化对象

[英]Detect when object is getting serialized

I have a class / object that uses a listener interface. 我有一个使用侦听器接口的类/对象。 As far as I understand, those can't be serialized, at least I get an NotSerializableException when trying to. 据我了解,那些无法序列化,至少在尝试时会收到NotSerializableException。

Can I detect from within the object when I's gettings serialized (some form of callback) so I can remove the listener from the object? 序列化(某种形式的回调)时,是否可以从对象中检测到,以便可以从对象中删除侦听器?

I know I can set the listener to null from outside of the object, but it would be easier the way I described. 我知道我可以从对象外部将侦听器设置为null,但是这样描述会更容易。

Don't do this. 不要这样 make your class implement Parcelable and provide the serialization methods yourself. 使您的类实现Parcelable并自己提供序列化方法。 Then you can decide which members get serialized and how that is done. 然后,您可以决定要序列化哪些成员以及如何进行序列化。

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

相关问题 通过套接字接收序列化对象时获取ClassNotFoundException - Getting ClassNotFoundException when receiving serialized object over socket Object 成员变量未序列化 - Object member variables not getting serialized 是否有一种内置的方法来检测序列化的java对象是否缺少字段? - is there a built-in way to detect if a serialized java object is missing fields? 有没有办法检测传入的序列化对象流是压缩的GZIPOutputStream还是简单的ObjectOutputStream? - Is there a way to detect if an incoming serialized object stream is GZIPOutputStream compressed or a simple ObjectOutputStream? 当object需要在spring开机序列化 - When object needs to be serialized in spring boot 在Servlet中读取序列化对象时出现EOFException - EOFException when reading serialized object in Servlet 序列化时Java GSON替换成员对象 - Java gson replace member object when serialized 反序列化序列化对象时,ClassNotFound异常 - ClassNotFound Exception when deserializing serialized object 当serialVersionId没有存储在序列化对象中时,反序列化过程如何知道序列化对象的serialVersionId? - How deserialization process is aware of serialVersionId of the serialized object when serialVersionId is not stored in the serialized object? 在服务器端扩展序列化对象时发生强制转换错误 - cast error when inflating a serialized object on server side
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM