code: public static byte[] convertJavaToText(Object source, MediaType sourceMediaType, MediaType destinationMediaType) {
        if (source == null) return null;
        if (sourceMediaType == null || destinationMediaType == null) {
           throw new NullPointerException("sourceMediaType and destinationMediaType cannot be null!");
        }
        Object decoded = decodeObjectContent(source, sourceMediaType);
  
        if (decoded instanceof byte[]) {
           return convertCharset(source, StandardCharsets.UTF_8, destinationMediaType.getCharset());
        } else {
           String asString = decoded.toString();
           return asString.getBytes(destinationMediaType.getCharset());
        }
     }
docs: Converts a java object to a text/plain representation.
  @param source Object to convert.
  @param sourceMediaType The MediaType for the source object.
  @param destinationMediaType The required text/plain specification.
  @return byte[] with the text/plain representation of the object with the requested charset.