/** * Take a list of Jackson ArrayNodes and merge their contents, preserving order. * * @param responses A list of pairs that encompass JSON nodes and response metadata * * @return A new pair holding the merged json and the aggregate request log context */ private Pair<JsonNode, LoggingContext> mergeResponses(List<Pair<JsonNode, LoggingContext>> responses) { JsonNodeFactory factory = new JsonNodeFactory(true); ArrayNode result = factory.arrayNode(); RequestLog.restore(logCtx); for (Pair<JsonNode, LoggingContext> entry : responses) { for (JsonNode jsonNode : entry.getKey()) { result.add(jsonNode); } RequestLog.accumulate(entry.getValue().getRequestLog()); } RequestLog updatedCtx = RequestLog.dump(); return new Pair<>(result, new LoggingContext(updatedCtx)); } }