Whether the default classloader ID is serializable
Of course, if the class has been loaded with a custom ClassLoader, then calling the “getClassLoader()” method of the result object will return the custom ClassLoader by default.
My question is, what happens if the same object is serialized, sent over the network, and then deserialized; Does calling “getClassLoader()” on a deserialized class still return a custom class loader?
Solution
My query is what happens if the same object is Serialized, sent over the network and then Deserialized; will a call to “getClassLoader()” on the Deserialised class still return the custom ClassLoader?
The classloader is not serialized. getClassLoader() will give you the class loader that ObjectInputStream is using.
From ObjectInputStream.resolveClass
The default implementation of the method in ObjectInputStream returns the call result
Class.forName(desc.getName(), false, loader)
where loader is
determined like this: if there is a method on the stack of the current thread whose declaration class is defined by a user-defined classloader (and is not generated to implement a reflection call), the loader is the corresponding classloader to the such method closest to the current execution frame; Otherwise, the loader is empty