@SuppressWarnings({ "unchecked" }) protected T fromBytes(byte[] bytes) { return (T) SerializationHelper.deserialize( bytes, getJavaType().getClassLoader() ); } }
private <T> T readSerFile() throws SerializationException, FileNotFoundException { log.readingCachedMappings( serFile ); return SerializationHelper.deserialize( new FileInputStream( serFile ) ); }
/** * <p>Deep clone an <code>Object</code> using serialization.</p> * <p/> * <p>This is many times slower than writing clone methods by hand * on all objects in your object graph. However, for complex object * graphs, or for those that don't support deep cloning this can * be a simple alternative implementation. Of course all the objects * must be <code>Serializable</code>.</p> * * @param object the <code>Serializable</code> object to clone * * @return the cloned object * * @throws SerializationException (runtime) if the serialization fails */ public static Object clone(Serializable object) throws SerializationException { LOG.trace( "Starting clone through serialization" ); if ( object == null ) { return null; } return deserialize( serialize( object ), object.getClass().getClassLoader() ); }
@Test public void testSerializeDeserialize() throws Exception { Class clazz = Thread.currentThread().getContextClassLoader().loadClass( "org.hibernate.test.util.SerializableThing" ); Object instance = clazz.newInstance(); // SerializableType.toBytes() logic, as called from SerializableType.disassemble() byte[] bytes = SerializationHelper.serialize( (Serializable) instance ); // SerializableType.fromBytes() logic, as called from SerializableType.assemble // NOTE : specifically we use Serializable.class.getClassLoader for the CL in many cases // which are the problematic cases Object instance2 = SerializationHelper.deserialize( bytes, Serializable.class.getClassLoader() ); assertEquals( instance.getClass(), instance2.getClass() ); assertEquals( instance.getClass().getClassLoader(), instance2.getClass().getClassLoader() ); assertEquals( custom, instance2.getClass().getClassLoader() ); }
public void testSerDeserClassUnknownToCustomLoader() throws Exception { Object instance = LockMode.OPTIMISTIC; assertSame( SerializationHelper.hibernateClassLoader(), instance.getClass().getClassLoader() ); // SerializableType.toBytes() logic, as called from SerializableType.disassemble() byte[] bytes = SerializationHelper.serialize( (Serializable) instance ); // SerializableType.fromBytes() logic, as called from SerializableType.assemble // NOTE : specifically we use custom so that LockType.class is not found // until the 3rd loader (because loader1 == loader2, the custom classloader) Object instance2 = SerializationHelper.deserialize( bytes, custom ); assertSame( instance.getClass(), instance2.getClass() ); assertSame( instance.getClass().getClassLoader(), instance2.getClass().getClassLoader() ); }
SerializationHelper.deserialize( SerializationHelper.serialize(s) ); s.close();
s.close(); foo = (Foo) SerializationHelper.deserialize( SerializationHelper.serialize(foo) );
SerializationHelper.deserialize( bytes );
dc = (DetachedCriteria) SerializationHelper.deserialize( bytes );
txn.commit(); final Session s3 = (Session) SerializationHelper.deserialize( SerializationHelper.serialize(s) ); s.close(); Session s4 = (Session) SerializationHelper.deserialize( SerializationHelper.serialize( s3 ) ); s3.close();
typeFactory = (TypeFactory) SerializationHelper.deserialize( typeFactoryBytes ); fail();
@Override @SuppressWarnings("unchecked") public <X> T wrap(X value, SharedSessionContractImplementor session) { if ( value == null ) { return null; } if ( value.getClass().equals( byte[].class ) ) { throw new UnsupportedOperationException( "Cannot unwrap Serializable to format other than byte[]" ); } final byte[] bytes = (byte[]) value; return (T) SerializationHelper.deserialize( bytes ); } }
@SuppressWarnings({ "unchecked" }) protected T fromBytes(byte[] bytes) { return (T) SerializationHelper.deserialize( bytes, getJavaTypeClass().getClassLoader() ); } }
@SuppressWarnings({ "unchecked" }) protected T fromBytes(byte[] bytes) { return (T) SerializationHelper.deserialize( bytes, getJavaTypeClass().getClassLoader() ); } }
private Object fromBytes(byte[] bytes) throws SerializationException { return SerializationHelper.deserialize( bytes, getReturnedClass().getClassLoader() ); }
private <T> T readSerFile() throws SerializationException, FileNotFoundException { log.readingCachedMappings( serFile ); return SerializationHelper.deserialize( new FileInputStream( serFile ) ); }
private Object fromBytes(byte[] bytes) throws SerializationException { return SerializationHelper.deserialize( bytes, getReturnedClass().getClassLoader() ); }
@SuppressWarnings({ "unchecked" }) protected T fromBytes(byte[] bytes) { if ( getJavaType() == null ) { throw new IllegalStateException( "Cannot read bytes for Serializable type" ); } return (T) SerializationHelper.deserialize( bytes, getJavaType().getClassLoader() ); } }
/** * <p>Deep clone an <code>Object</code> using serialization.</p> * * <p>This is many times slower than writing clone methods by hand * on all objects in your object graph. However, for complex object * graphs, or for those that don't support deep cloning this can * be a simple alternative implementation. Of course all the objects * must be <code>Serializable</code>.</p> * * @param object the <code>Serializable</code> object to clone * * @return the cloned object * * @throws SerializationException (runtime) if the serialization fails */ public static Object clone(Serializable object) throws SerializationException { LOG.trace( "Starting clone through serialization" ); if ( object == null ) { return null; } return deserialize( serialize( object ), object.getClass().getClassLoader() ); }
/** * <p>Deep clone an <code>Object</code> using serialization.</p> * * <p>This is many times slower than writing clone methods by hand * on all objects in your object graph. However, for complex object * graphs, or for those that don't support deep cloning this can * be a simple alternative implementation. Of course all the objects * must be <code>Serializable</code>.</p> * * @param object the <code>Serializable</code> object to clone * * @return the cloned object * * @throws SerializationException (runtime) if the serialization fails */ public static Object clone(Serializable object) throws SerializationException { LOG.trace( "Starting clone through serialization" ); if ( object == null ) { return null; } return deserialize( serialize( object ), object.getClass().getClassLoader() ); }