code: public static String serialize(Object obj) throws ApiException {
          try {
              if (obj != null)
                      if (obj instanceof String) {
                          // This assumes that we receive json as a string
                          return (String) obj;
                  } else {
                          return JsonUtil.getJsonMapper().writeValueAsString(obj);
                  }
              else
                  return null;
          }
          catch (Exception e) {
              throw new ApiException(500, e.getMessage());
          }
      }
docs: Serialize an Object.
  @param obj the Object to serialize
  @throws APIException if an exception occurs during serialization