public static byte[] serialize(Object obj){
  try {
    ByteArrayOutputStream out=new ByteArrayOutputStream();
    ObjectOutputStream os=new ObjectOutputStream(out);
    os.writeObject(obj);
    return out.toByteArray();
  }
 catch (  Throwable e) {
    throw DataUtils.newIllegalArgumentException("Could not serialize {0}",obj,e);
  }
}

public static byte [ ] serialize ( Object obj ) { try { ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; ObjectOutputStream os = new ObjectOutputStream ( out ) ; os . writeObject ( obj ) ; return out . toByteArray ( ) ; } catch ( Throwable e ) { throw DataUtils . newIllegalArgumentException ( "Could not serialize {0}" , obj , e ) ; } }
serialize the object to a byte array .
