@Test public void http_200_uses_delegate_decoder() throws IOException { when(delegate.decode(any(), eq(String.class))).thenReturn("text response"); Response http200 = Response.create( 200, "OK", ImmutableMap.of(HttpHeaders.CONTENT_TYPE, ImmutableSet.of(MediaType.TEXT_PLAIN)), "text response", StandardCharsets.UTF_8); emptyContainerDecoder.decode(http200, String.class); verify(delegate, times(1)).decode(any(), any()); }
@Override public Object decode(Response response, Type type) throws IOException { Object delegateResult = delegate.decode(response, type); if (response.status() == 204 || (response.status() == 200 && delegateResult == null)) { @Nullable Object object = blankInstanceCache.get(type); return Preconditions.checkNotNull( object, "Received HTTP 204 but unable to construct an empty instance for return type", SafeArg.of("type", type)); } else { return delegateResult; } }
EmptyContainerDecoder implements Decoder { @Override public Object decode(Response response, Type type) throws IOException { Object delegateResult = delegate.decode(response, type); if (response.status() == 204 || (response.status() == 200 && delegateResult == null)) { @Nullable Object object = blankInstanceCache.get(type); return Preconditions.checkNotNull( object, "Received HTTP 204 but unable to construct an empty instance for return type", SafeArg.of("type", type)); } else { return delegateResult; } } }
EmptyContainerDecoder implements Decoder { @Override public Object decode(Response response, Type type) throws IOException { Object delegateResult = delegate.decode(response, type); if (response.status() == 204 || (response.status() == 200 && delegateResult == null)) { @Nullable Object object = blankInstanceCache.get(type); return Preconditions.checkNotNull( object, "Received HTTP 204 but unable to construct an empty instance for return type", SafeArg.of("type", type)); } else { return delegateResult; } } EmptyContainerDecoder(ObjectMapper mapper, Decoder delegate); }
EmptyContainerDecoder implements Decoder { @Override public Object decode(Response response, Type type) throws IOException { Object delegateResult = delegate.decode(response, type); if (response.status() == 204 || (response.status() == 200 && delegateResult == null)) { @Nullable Object object = blankInstanceCache.get(type); return Preconditions.checkNotNull( object, "Received HTTP 204 but unable to construct an empty instance for return type", SafeArg.of("type", type)); } else { return delegateResult; } } EmptyContainerDecoder(ObjectMapper mapper, Decoder delegate); @Override Object decode(Response response, Type type); }
EmptyContainerDecoder implements Decoder { @Override public Object decode(Response response, Type type) throws IOException { Object delegateResult = delegate.decode(response, type); if (response.status() == 204 || (response.status() == 200 && delegateResult == null)) { @Nullable Object object = blankInstanceCache.get(type); return Preconditions.checkNotNull( object, "Received HTTP 204 but unable to construct an empty instance for return type", SafeArg.of("type", type)); } else { return delegateResult; } } EmptyContainerDecoder(ObjectMapper mapper, Decoder delegate); @Override Object decode(Response response, Type type);  }