code: private ByteArrayOutputStream toByteStream(Object item, boolean pretty) throws IOException {
      ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
      JsonGenerator generator = createJsonGenerator(byteStream, Charsets.UTF_8);
      if (pretty) {
        generator.enablePrettyPrint();
      }
      generator.serialize(item);
      generator.flush();
      return byteStream;
    }
docs: Returns a UTF-8 byte array output stream of the serialized JSON representation for the given
  item using {@link JsonGenerator#serialize(Object)}.
  
  @param item data key/value pairs
  @param pretty whether to return a pretty representation
  @return serialized JSON string representation