Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.io.NotSerializableException for unknown classes

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.

like image 576
Aleksandar Avatar asked Jun 27 '26 22:06

Aleksandar


1 Answers

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.

like image 139
LeoPold1447 Avatar answered Jun 30 '26 13:06

LeoPold1447