java - Sharing objects between class loader using serialization -
i have test load modules of project in custom class loader (for testing purposes). 1 of method in such object gets custom object argument, , if i'm passing test class (which has been loaded default classloader), method in object loaded custom class loader i'm getting type mismatch exception.
i have thought can avoid issue because fortunately custom object implements serializable (i thought serilizae object test class , deserialize in custom classloader , pass method). however, since serilization utils classes loaded parent class loader, produced object (deserialization output) still pointed default class loader.
how can deserialize object in custom class loader? code:
class<?> serialclassdefinition = classloader.loadclass("org.apache.commons.lang.serializationutils"); final byte[] serializeddestdata = serializationutils.serialize(sampledata); final method deserializemethod = serialclassdefinition.getdeclaredmethod("deserialize", byte[].class); final object oldsmapledata = deserializemethod.invoke(null, serializedsampledata); homecoming (invoke(stringa, stringb, stringc, oldsampledata, isaaa));
java serialization classloader
No comments:
Post a Comment