@Test public void shouldParseJsonArray() throws Exception { final BiFunction<HttpRequestBase, HttpResponse, Set<String>> extractStatuses = toJson(new ObjectMapper()).andThen(jsonNode -> { final Iterator<JsonNode> elements = jsonNode.elements(); Set<String> statuses = new HashSet<>(); while (elements.hasNext()) { final JsonNode element = elements.next(); statuses.add(element.get("status").asText()); } return statuses; }); final BasicHttpResponse response = buildResponse(); response.setEntity(new StringEntity("[{\"status\":\"OK\"}, {\"status\":\"OK\"}, {\"status\":\"CANCEL\"}]")); final HttpGet request = buildRequest(); final Set<String> statuses = extractStatuses.apply(request, response); assertEquals(2, statuses.size()); assertTrue(statuses.contains("OK")); assertTrue(statuses.contains("CANCEL")); }
public static BiFunction<HttpRequestBase, HttpResponse, JsonNode> toJson(ObjectMapper mapper) { return (request, response) -> { try (InputStream content = response.getEntity().getContent()) { JsonNode jsonNode = mapper.readTree(content); if (jsonNode == null) { throw new IllegalArgumentException("Source should not be empty"); } return jsonNode; } catch (Exception e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } finally { request.releaseConnection(); } }; }
Defaults { public static BiFunction<HttpRequestBase, HttpResponse, JsonNode> toJson(ObjectMapper mapper) { return (request, response) -> { try (InputStream content = response.getEntity().getContent()) { JsonNode jsonNode = mapper.readTree(content); if (jsonNode == null) { throw new IllegalArgumentException("Source should not be empty"); } return jsonNode; } catch (Exception e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } finally { request.releaseConnection(); } }; } }
Defaults { public static BiFunction<HttpRequestBase, HttpResponse, JsonNode> toJson(ObjectMapper mapper) { return (request, response) -> { try (InputStream content = response.getEntity().getContent()) { JsonNode jsonNode = mapper.readTree(content); if (jsonNode == null) { throw new IllegalArgumentException("Source should not be empty"); } return jsonNode; } catch (Exception e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } finally { request.releaseConnection(); } }; } private  Defaults(); }
Defaults { public static BiFunction<HttpRequestBase, HttpResponse, JsonNode> toJson(ObjectMapper mapper) { return (request, response) -> { try (InputStream content = response.getEntity().getContent()) { JsonNode jsonNode = mapper.readTree(content); if (jsonNode == null) { throw new IllegalArgumentException("Source should not be empty"); } return jsonNode; } catch (Exception e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } finally { request.releaseConnection(); } }; } private  Defaults(); static Function<Exception, RuntimeException> passthrough(); static BiFunction<HttpRequestBase, HttpResponse, T> asNull(); static BiFunction<HttpRequestBase, HttpResponse, String> asString(); static BiFunction<HttpRequestBase, HttpResponse, String> emptyString(); static BiFunction<HttpRequestBase, HttpResponse, InputStream> emptyStream(); static BiFunction<HttpRequestBase, HttpResponse, InputStream> pipeStream(); static BiFunction<HttpRequestBase, HttpResponse, T> convertResponse(ObjectMapper mapper,
            Class<T> clazz); static BiFunction<HttpRequestBase, HttpResponse, T> convertResponse(ObjectMapper mapper,
            TypeReference<T> typeReference); static BiFunction<HttpRequestBase, HttpResponse, T> convertResponse(ObjectMapper mapper,
            TypeReference<T> typeReference, Function<Exception, T> errorHandler); static BiFunction<HttpRequestBase, HttpResponse, JsonNode> toJson(ObjectMapper mapper); static BiFunction<HttpRequestBase, HttpResponse, S> iterate(Class<T> clazz, ObjectMapper mapper,
            Function<Iterator<T>, S> convert); static ResponseEntity<String> getResponseEntity(HttpStatus status, HttpResponse response); }
Defaults { public static BiFunction<HttpRequestBase, HttpResponse, JsonNode> toJson(ObjectMapper mapper) { return (request, response) -> { try (InputStream content = response.getEntity().getContent()) { JsonNode jsonNode = mapper.readTree(content); if (jsonNode == null) { throw new IllegalArgumentException("Source should not be empty"); } return jsonNode; } catch (Exception e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } finally { request.releaseConnection(); } }; } private  Defaults(); static Function<Exception, RuntimeException> passthrough(); static BiFunction<HttpRequestBase, HttpResponse, T> asNull(); static BiFunction<HttpRequestBase, HttpResponse, String> asString(); static BiFunction<HttpRequestBase, HttpResponse, String> emptyString(); static BiFunction<HttpRequestBase, HttpResponse, InputStream> emptyStream(); static BiFunction<HttpRequestBase, HttpResponse, InputStream> pipeStream(); static BiFunction<HttpRequestBase, HttpResponse, T> convertResponse(ObjectMapper mapper,
            Class<T> clazz); static BiFunction<HttpRequestBase, HttpResponse, T> convertResponse(ObjectMapper mapper,
            TypeReference<T> typeReference); static BiFunction<HttpRequestBase, HttpResponse, T> convertResponse(ObjectMapper mapper,
            TypeReference<T> typeReference, Function<Exception, T> errorHandler); static BiFunction<HttpRequestBase, HttpResponse, JsonNode> toJson(ObjectMapper mapper); static BiFunction<HttpRequestBase, HttpResponse, S> iterate(Class<T> clazz, ObjectMapper mapper,
            Function<Iterator<T>, S> convert); static ResponseEntity<String> getResponseEntity(HttpStatus status, HttpResponse response);  }