ClassLoader testClassLoader = ObjectInputStreamWithClassLoaderTest.newClassLoader(obj.getClass());
Thread.currentThread().setContextClassLoader(testClassLoader);
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
org.hornetq.utils.ObjectInputStreamWithClassLoader ois = new ObjectInputStreamWithClassLoader(bais);
Object deserializedObj = ois.readObject();
Assert.assertNotSame(obj, deserializedObj);
Assert.assertNotSame(obj.getClass(), deserializedObj.getClass());
Assert.assertNotSame(obj.getClass().getClassLoader(), deserializedObj.getClass().getClassLoader());
Assert.assertSame(testClassLoader, deserializedObj.getClass().getClassLoader());