code: public byte[] serializeToBytes(final Serializable o) {
          byte[] bytes = null;
          try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
               final ObjectOutputStream oos = new ObjectOutputStream(baos)) {
              oos.writeObject(o);
              oos.flush();
              bytes = baos.toByteArray();
          } catch (final IOException e) {
              logger.warn("cannot Java serialize object", e);
          }
          return bytes;
      }
docs: Serialize a Java object into a bytes array.
  
  @param o the object to serialize
  @return the bytes array of the serialized object