Java.io.NotSerializableException for unknown classes

I am trying to make my classes Serializable. All my classes are there, but still this is throwing me a NotSerializableException for some other classes that I cannot find in it (e.g. com.sun.java.swing.plaf.windows.XPStyle, WClipboard).

What can I do and how can I bypass these classes when serializing or making them Serializable?

solved

The problem was the LookAndFeel that I was using in my JFrames and JDialogs (problem with XPStyle

). Second ( WClipboard

), it was used by a third party class I got from here. This class uses the clipboard.

I made a Clipboard field transient

and LookAndFeel I couldn't handle just deleting it.

+3


source to share


1 answer


If you don't want the data to be serialized for persistence or transport, you can declare those transient

However, if you need data in these Objects (classes) to be stored, transported over TCP / UDP, etc. than you might want the extend

class and implement your own interpretation so that you can then declare your extended class Serializable

.




The end option might be to use a different method Serialization

like that provided by FST , Kryo , etc. Often these Serialization libraries can use Reflection

Serialize objects, which the default Java implementation cannot.

+1


source







All Articles