@SuppressWarnings("unchecked")
 protected <T extends ApiResponse<?, ?>> T postInternal(
     Class<? extends ApiResponse<?, ?>> clazz,
     String root,
     String path,
     Map<String, String> headers,
     Object data,
     String mediaType) {
   try {
     WebResource webResource =
         getClient().resource(root).path(configuration.getVersion()).path(path);
     WebResource.Builder builder = webResource.getRequestBuilder();
     builder = builder.header("Content-Type", mediaType);
     if (headers != null) {
       for (String key : headers.keySet()) {
         builder = builder.header(key, headers.get(key));
       }
     }
     logger.fine(data.toString());
     String response = builder.accept(mediaType).post(String.class, data);
     logger.fine(response);
     return (T) TypeHelper.INSTANCE.getObjectMapper().readValue(response, clazz);
   } catch (BaseSpaceException bs) {
     throw bs;
   } catch (Throwable t) {
     t.printStackTrace();
     throw new RuntimeException(t);
   }
 }
 @SuppressWarnings("unchecked")
 @Override
 public <T extends ApiResponse<?, ?>> T getResponse(
     Class<? extends ApiResponse<?, ?>> clazz,
     String root,
     String path,
     Mappable params,
     Map<String, String> headers) {
   try {
     return (T)
         TypeHelper.INSTANCE
             .getObjectMapper()
             .readValue(getStringResponse(root, path, params, headers), clazz);
   } catch (BaseSpaceException bs) {
     throw bs;
   } catch (RuntimeException t) {
     throw t;
   } catch (Throwable t) {
     throw new RuntimeException(t);
   }
 }
  @SuppressWarnings("unchecked")
  @Override
  public <T extends ApiResponse<?, ?>> T putFile(
      Class<? extends ApiResponse<?, ?>> clazz,
      String path,
      Map<String, String> headers,
      InputStream file) {
    try {
      WebResource resource =
          getClient()
              .resource(
                  UriBuilder.fromUri(getConfiguration().getApiRootUri())
                      .path(getConfiguration().getVersion())
                      .path(path)
                      .build());

      WebResource.Builder builder = resource.getRequestBuilder();
      if (headers != null) {
        for (String key : headers.keySet()) {
          builder = builder.header(key, headers.get(key));
        }
      }
      builder =
          builder
              .type(MediaType.APPLICATION_OCTET_STREAM)
              .accept(MediaType.APPLICATION_JSON)
              .entity(file);

      String response = builder.put(String.class);
      logger.fine(response);
      return (T) TypeHelper.INSTANCE.getObjectMapper().readValue(response, clazz);
    } catch (BaseSpaceException bs) {
      throw bs;
    } catch (RuntimeException t) {
      throw t;
    } catch (Throwable t) {
      throw new RuntimeException(t);
    }
  }
 @Override
 public ObjectMapper getMapper() {
   return TypeHelper.INSTANCE.getObjectMapper();
 }