I'm trying to make my classes Serializable. All of my classes are, but still it throws me NotSerializableException for some other classes that I can't find it's usages (e.g. com.sun.java.swing.plaf.windows.XPStyle, WClipboard).
What can I do and how can I bypass these classes when serializing or make them Serializable?
SOLVED
The problem was in LookAndFeel I have used in my JFrames and JDialogs (problem with XPStyle). Second one (WClipboard), it was used by third party class I got from here. This class uses Clipboard.
I made Clipboard field transient and LookAndFeel I couldn't manage, just by deleting it.
If you do not want the data to be serialized for persistence or transfer, than you can declare those transient
However, if you need the data in those Objects (classes) to be persisted, transported via TCP / UDP, etc. than you might want to extend the class, and implement your own interpretation of it, so that you can then declare your extended class Serializable.
A final option might be to use a different method of Serialization, such as those provided by FST, Kryo, etc. Often times these Serialization libraries can use Reflection to Serialize Objects that the default Java implementation cannot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With