コード例 #1
0
  public T getObject(String endpoint, Map<String, String> params, Class clazz) {
    RestTemplate template = new RestTemplate();
    String finalUrl = URLUtils.buildUrl(endpoint, params);
    log.info("Calling endpoint " + finalUrl + ".");
    @SuppressWarnings("unchecked")
    ResponseEntity<T> object =
        (ResponseEntity<T>) template.exchange(finalUrl, HttpMethod.GET, RequestEntity.EMPTY, clazz);

    return object.getBody();
  }
コード例 #2
0
  @SuppressWarnings("unchecked")
  @Override
  public List<T> getList(String endpoint, Map<String, String> params, Class clazz) {
    RestTemplate template = new RestTemplate();
    String finalUrl = URLUtils.buildUrl(endpoint, params);
    log.info("Calling endpoint " + finalUrl + ".");
    T[] e = (T[]) Array.newInstance(clazz, 1);
    ResponseEntity<T[]> list =
        (ResponseEntity<T[]>)
            template.exchange(finalUrl, HttpMethod.GET, RequestEntity.EMPTY, e.getClass());

    return Arrays.asList(list.getBody());
  }