"John Keiser" <[EMAIL PROTECTED]> writes:

>       Does anyone know if there is a way to load a serialized Object using an
> explicit ClassLoader?  I need it for Beans.instantiate().
> --John Keiser

Subclass ObjectInputStream and override resolveClass() to use the
given ClassLoader:

public static Object readObjectWithClassLoader( final ClassLoader cl )
{
  ObjectInputStream in =
    new ObjectInputStream()
    {
      public resolveClass( ObjectStreamClass osc )
      {
        return cl.loadClass( osc.getName() );
      }
    };

  return in.readObject();
}

Actually, this won't work because subclasses of ObjectInputStream must
call ObjectInputStream(InputStream) unless they are overriding
readObject() (in 1.2),  but the idea is right.

-- 
Geoff Berry

Reply via email to