code: public static byte[] toBytes(Object value) {
          try {
              return mapper.writeValueAsBytes(value);
          } catch (Exception e) {
              System.out.println(e.getMessage());
              throw new IllegalArgumentException(
                String.format("Could not transform to bytes: %s", e.getMessage()));
          }
      }
docs: Convert an Object to an array of bytes.