public static byte [ ] serialize ( Object object ) { if ( object == null ) { return null ; } ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; try { ObjectOutputStream oos = new ObjectOutputStream ( baos ) ; oos . writeObject ( object ) ; oos . flush ( ) ; } catch ( IOException ex ) { throw new IllegalArgumentException ( "Failed to serialize object of type: " + object . getClass ( ) , ex ) ; } return baos . toByteArray ( ) ; }
Serialize the given object to a byte array .