I have a serializable class which has some members injected from guice module. However, these members are unserializable and I can't force the declaration of them with Serializable interface. How shall I write readObject and writeObject functions for this class to support the serializing the instance of this class?
You can either declare these fields as transient
to prevent automatic serialization or implement your own readObject
and writeObject
. The implementation will depend on your application. If after deserialization you can stand without the not serializable members, just ignore them. If you need them you have to find a way to get them.
In your case these are Guice-injected objects. If you are planning to deserialize your object in context of Guice you have to inject these dependencies. I do not know Guice enough but in Spring I know 2 ways:
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다