this.context = context;
if (this.bytes != null) {
ByteArrayInputStream input = new ByteArrayInputStream(this.bytes);
SimpleDataInput data = new SimpleDataInput(Marshalling.createByteInput(input));
int version = data.readInt();
Unmarshaller unmarshaller = context.createUnmarshaller(version);
try {
unmarshaller.start(data);
// Workaround for AS7-2496
ClassLoader currentLoader = null;
ClassLoader contextLoader = context.getContextClassLoader(version);
if (contextLoader != null) {
currentLoader = getCurrentThreadContextClassLoader();
setCurrentThreadContextClassLoader(contextLoader);
}
try {
this.object = (T) unmarshaller.readObject();
} finally {
if (contextLoader != null) {
setCurrentThreadContextClassLoader(currentLoader);
}
}
unmarshaller.finish();
this.bytes = null; // Free up memory
} finally {
unmarshaller.close();
}
}
}
return this.object;
}