JsonHttpUtil { public static <REQUEST_T, RESPONSE_T> RESPONSE_T postCollection(String url, REQUEST_T requestBodyObject, TypeReference<RESPONSE_T> typeReference) throws Exception { String requestBodyStr = JsonUtil.toJson(requestBodyObject); String responseStr = HttpUtil.post(url, requestBodyStr); return JsonUtil.toCollectionBean(responseStr, typeReference); }  static RESPONSE_T postOne(String url, REQUEST_T requestBodyObject, Class<RESPONSE_T> responseType); static RESPONSE_T postOne(String url, Class<RESPONSE_T> responseType); static RESPONSE_T postCollection(String url, REQUEST_T requestBodyObject, TypeReference<RESPONSE_T> typeReference); static RESPONSE_T postCollection(String url, TypeReference<RESPONSE_T> typeReference); static RESPONSE_T getOne(String url, Class<RESPONSE_T> responseType); static RESPONSE_T getCollection(String url, TypeReference<RESPONSE_T> typeReference);  }
@Test public void testPostCollection() throws Exception { String url = buildUrl("postList"); List<User> userList = JsonHttpUtil.postCollection(url, new TypeReference<List<User>>() { }); Assert.hasLength(userList.get(0).getName()); }
@Test public void testPostCollectionWithRequestBody() throws Exception { String url = buildUrl("postListWithRequestBody"); List<User> userList = JsonHttpUtil.postCollection(url, USER, new TypeReference<List<User>>() { }); Assert.hasLength(userList.get(0).getName()); }