docs: public static <T> T convertIfNecessary(Object target, Class<T> type) {
          if (type.isInstance(target)) {
              return type.cast(target);
          }
  
          if (Source.class.isAssignableFrom(type)) {
              if (target.getClass().isAssignableFrom(String.class)) {
                  return (T) new StringSource(String.valueOf(target));
              } else if (target.getClass().isAssignableFrom(Node.class)) {
                  return (T) new DOMSource((Node) target);
              } else if (target.getClass().isAssignableFrom(InputStreamSource.class)) {
                  try {
                      return (T) new StreamSource(((InputStreamSource)target).getInputStream());
                  } catch (IOException e) {
                      log.warn("Failed to create stream source from object", e);
                  }
              }
          }
  
          if (MultiValueMap.class.isAssignableFrom(type)) {
              String mapString = String.valueOf(target);
  
              Properties props = new Properties();
              try {
                  props.load(new StringReader(mapString.substring(1, mapString.length() - 1).replaceAll("\\]\\s*", "]\n")));
              } catch (IOException e) {
                  throw new CitrusRuntimeException("Failed to reconstruct object of type map", e);
              }
              MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
              for (Map.Entry<Object, Object> entry : props.entrySet()) {
                  String arrayString = String.valueOf(entry.getValue()).replaceAll("^\\[", "").replaceAll("\\]$", "").replaceAll(",\\s", ",");
                  map.add(entry.getKey().toString(), StringUtils.commaDelimitedListToStringArray(String.valueOf(arrayString)));
              }
  
              return (T) map;
          }
  
          if (Map.class.isAssignableFrom(type)) {
              String mapString = String.valueOf(target);
  
              Properties props = new Properties();
              try {
                  props.load(new StringReader(mapString.substring(1, mapString.length() - 1).replaceAll(",\\s*", "\n")));
              } catch (IOException e) {
                  throw new CitrusRuntimeException("Failed to reconstruct object of type map", e);
              }
              Map<String, Object> map = new LinkedHashMap<>();
              for (Map.Entry<Object, Object> entry : props.entrySet()) {
                  map.put(entry.getKey().toString(), entry.getValue());
              }
  
              return (T) map;
          }
  
          if (String[].class.isAssignableFrom(type)) {
              String arrayString = String.valueOf(target).replaceAll("^\\[", "").replaceAll("\\]$", "").replaceAll(",\\s", ",");
              return (T) StringUtils.commaDelimitedListToStringArray(String.valueOf(arrayString));
          }
  
          if (List.class.isAssignableFrom(type)) {
              String listString = String.valueOf(target).replaceAll("^\\[", "").replaceAll("\\]$", "").replaceAll(",\\s", ",");
              return (T) Arrays.asList(StringUtils.commaDelimitedListToStringArray(String.valueOf(listString)));
          }
  
          if (byte[].class.isAssignableFrom(type)) {
              if (target instanceof String) {
                  try {
                      return (T) String.valueOf(target).getBytes(Citrus.CITRUS_FILE_ENCODING);
                  } catch (UnsupportedEncodingException e) {
                      return (T) String.valueOf(target).getBytes();
                  }
              } else if (target instanceof ByteBuffer) {
                  return (T) ((ByteBuffer) target).array();
              } else if (target instanceof ByteArrayInputStream) {
                  try {
                      return (T) StreamUtils.copyToByteArray((ByteArrayInputStream) target);
                  } catch (IOException e) {
                      throw new CitrusRuntimeException("Failed to convert input stream to byte[]");
                  }
              }
          }
  
          if (InputStream.class.isAssignableFrom(type)) {
              if (target instanceof InputStream) {
                  return (T) target;
              } else if (target instanceof byte[]) {
                  return (T) new ByteArrayInputStream((byte[]) target);
              } else if (target instanceof String) {
                  try {
                      return (T) new ByteArrayInputStream(String.valueOf(target).getBytes(Citrus.CITRUS_FILE_ENCODING));
                  } catch (UnsupportedEncodingException e) {
                      return (T) new ByteArrayInputStream(String.valueOf(target).getBytes());
                  }
              } else {
                  try {
                      return (T) new ByteArrayInputStream(target.toString().getBytes(Citrus.CITRUS_FILE_ENCODING));
                  } catch (UnsupportedEncodingException e) {
                      return (T) new ByteArrayInputStream(target.toString().getBytes());
                  }
              }
          }