@Test public void shouldDeserializeWithAppropriateDeserializer() throws Exception { InputStream stream = mock(InputStream.class); when(mockResponse.getContentType()).thenReturn("mime2"); when(mockResponse.getExpectedType()).thenReturn((Class)int.class); when(mockResponse.getExpectedGenericType()).thenReturn(int.class); when(mockResponse.getCharset()).thenReturn(UTF8); when(mockResponse.asStream()).thenReturn(stream); when(mockDeserializerMime2.deserialize(int.class, int.class, stream, UTF8)).thenReturn(123); int actual = toTest.<Integer>deserialize(mockResponse); assertEquals(123, actual); }
public <T> T deserialize(Response response) throws Exception { String mimeType = response.getContentType(); isTrue(mimeDeserializerRegistry.contains(mimeType), MIME_TYPE_NOT_FOUND_ERROR, mimeType); LOG.debug("Trying to deserialize response to Mime Type: %s.", mimeType); return mimeDeserializerRegistry.get(mimeType).<T>deserialize( (Class<T>) response.getExpectedType(), response.getExpectedGenericType(), response.asStream(), response.getCharset()); }
ResponseDeserializerByMimeType implements ResponseDeserializer { public <T> T deserialize(Response response) throws Exception { String mimeType = response.getContentType(); isTrue(mimeDeserializerRegistry.contains(mimeType), MIME_TYPE_NOT_FOUND_ERROR, mimeType); LOG.debug("Trying to deserialize response to Mime Type: %s.", mimeType); return mimeDeserializerRegistry.get(mimeType).<T>deserialize( (Class<T>) response.getExpectedType(), response.getExpectedGenericType(), response.asStream(), response.getCharset()); } }
ResponseDeserializerByMimeType implements ResponseDeserializer { public <T> T deserialize(Response response) throws Exception { String mimeType = response.getContentType(); isTrue(mimeDeserializerRegistry.contains(mimeType), MIME_TYPE_NOT_FOUND_ERROR, mimeType); LOG.debug("Trying to deserialize response to Mime Type: %s.", mimeType); return mimeDeserializerRegistry.get(mimeType).<T>deserialize( (Class<T>) response.getExpectedType(), response.getExpectedGenericType(), response.asStream(), response.getCharset()); } ResponseDeserializerByMimeType(ComponentRegistry<String, Deserializer> mimeDeserializerRegistry); }
ResponseDeserializerByMimeType implements ResponseDeserializer { public <T> T deserialize(Response response) throws Exception { String mimeType = response.getContentType(); isTrue(mimeDeserializerRegistry.contains(mimeType), MIME_TYPE_NOT_FOUND_ERROR, mimeType); LOG.debug("Trying to deserialize response to Mime Type: %s.", mimeType); return mimeDeserializerRegistry.get(mimeType).<T>deserialize( (Class<T>) response.getExpectedType(), response.getExpectedGenericType(), response.asStream(), response.getCharset()); } ResponseDeserializerByMimeType(ComponentRegistry<String, Deserializer> mimeDeserializerRegistry); T deserialize(Response response); }
ResponseDeserializerByMimeType implements ResponseDeserializer { public <T> T deserialize(Response response) throws Exception { String mimeType = response.getContentType(); isTrue(mimeDeserializerRegistry.contains(mimeType), MIME_TYPE_NOT_FOUND_ERROR, mimeType); LOG.debug("Trying to deserialize response to Mime Type: %s.", mimeType); return mimeDeserializerRegistry.get(mimeType).<T>deserialize( (Class<T>) response.getExpectedType(), response.getExpectedGenericType(), response.asStream(), response.getCharset()); } ResponseDeserializerByMimeType(ComponentRegistry<String, Deserializer> mimeDeserializerRegistry); T deserialize(Response response);  }