@Test public void testValidJson() { User user = new User("Joe", 25); String json = codec.toJson(user); JsonResponse<User> response = handler.handle(null, mockResponse().contentType(JSON_UTF_8).body(json).build()); assertTrue(response.hasValue()); assertEquals(response.getJsonBytes(), json.getBytes(StandardCharsets.UTF_8)); assertEquals(response.getJson(), json); assertEquals(response.getValue().getName(), user.getName()); assertEquals(response.getValue().getAge(), user.getAge()); assertNotSame(response.getJson(), response.getJson()); assertNotSame(response.getJsonBytes(), response.getJsonBytes()); assertNotSame(response.getResponseBytes(), response.getResponseBytes()); assertNotSame(response.getResponseBody(), response.getResponseBody()); assertEquals(response.getResponseBytes(), response.getJsonBytes()); assertEquals(response.getResponseBody(), response.getJson()); }
@Override public JsonResponse<T> handle(Request request, Response response) { byte[] bytes = readResponseBytes(response); String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_JSON)) { return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), bytes); } return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, bytes); }
FullJsonResponseHandler implements ResponseHandler<JsonResponse<T>, RuntimeException> { @Override public JsonResponse<T> handle(Request request, Response response) { byte[] bytes = readResponseBytes(response); String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_JSON)) { return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), bytes); } return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, bytes); } }
FullJsonResponseHandler implements ResponseHandler<JsonResponse<T>, RuntimeException> { @Override public JsonResponse<T> handle(Request request, Response response) { byte[] bytes = readResponseBytes(response); String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_JSON)) { return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), bytes); } return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, bytes); } private  FullJsonResponseHandler(JsonCodec<T> jsonCodec); }
FullJsonResponseHandler implements ResponseHandler<JsonResponse<T>, RuntimeException> { @Override public JsonResponse<T> handle(Request request, Response response) { byte[] bytes = readResponseBytes(response); String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_JSON)) { return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), bytes); } return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, bytes); } private  FullJsonResponseHandler(JsonCodec<T> jsonCodec); static FullJsonResponseHandler<T> createFullJsonResponseHandler(JsonCodec<T> jsonCodec); @Override JsonResponse<T> handleException(Request request, Exception exception); @Override JsonResponse<T> handle(Request request, Response response); }
FullJsonResponseHandler implements ResponseHandler<JsonResponse<T>, RuntimeException> { @Override public JsonResponse<T> handle(Request request, Response response) { byte[] bytes = readResponseBytes(response); String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_JSON)) { return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), bytes); } return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, bytes); } private  FullJsonResponseHandler(JsonCodec<T> jsonCodec); static FullJsonResponseHandler<T> createFullJsonResponseHandler(JsonCodec<T> jsonCodec); @Override JsonResponse<T> handleException(Request request, Exception exception); @Override JsonResponse<T> handle(Request request, Response response);  }