public static byte[] toByteArray(Object obj){
  int len=(int)sizeOf(obj);
  byte[] bytes=new byte[len];
  unsafe.copyMemory(obj,0,bytes,Unsafe.ARRAY_BYTE_BASE_OFFSET,bytes.length);
  return bytes;
}

public static byte [ ] toByteArray ( Object obj ) { int len = ( int ) sizeOf ( obj ) ; byte [ ] bytes = new byte [ len ] ; unsafe . copyMemory ( obj , 0 , bytes , Unsafe . ARRAY_BYTE_BASE_OFFSET , bytes . length ) ; return bytes ; }
returns the object as a byte array , including header , padding and all fields .
