@SuppressWarnings("unchecked")
  public <T> T deserialize(HttpResponse response, TypeReference<T> valueType) throws ApiException, IOException {
    if (valueType == null) {
      return null;
    }
    HttpEntity entity = response.getEntity();
    Type valueRawType = valueType.getType();
    if (valueRawType.equals(byte[].class)) {
      return (T) EntityUtils.toByteArray(entity);
    } else if (valueRawType.equals(File.class)) {
      return (T) downloadFileFromResponse(response);
    }
    String mimeType = getResponseMimeType(response);
    if (mimeType == null || isJsonMime(mimeType)) {
      // Assume json if no mime type
      // convert input stream to string
      Scanner s = new Scanner(entity.getContent()).useDelimiter("\\A");
      String content = (String) (s.hasNext() ? s.next() : "");

      if ("".equals(content)) { // returns null for empty body
        return null;
      }

      return objectMapper.readValue(content, valueType);
    } else if ("text/plain".equalsIgnoreCase(mimeType)) {
      // convert input stream to string
      Scanner s = new Scanner(entity.getContent()).useDelimiter("\\A");
      return (T) (s.hasNext() ? s.next() : "");
    } else {
      throw new ApiException(
          "Deserialization for content type '" + mimeType + "' not supported for type '" + valueType + "'",
          response.getStatusLine().getStatusCode(),
          responseHeaders,
          EntityUtils.toString(entity)
      );
    }
  }
Deserialize response body to Java object according to the Content-Type.

@param <T> Type
@param response Response
@param valueType Return type
@return Deserialized object
@throws ApiException API exception
@throws IOException IO exception
plc4j/drivers/ctrlx/src/main/java/org/apache/plc4x/java/ctrlx/readwrite/rest/datalayer/ApiClient.java