@Test public void shouldDeserializeWithAppropriateDeserializer() throws Exception { InputStream stream = mock(InputStream.class); when(mockResponse.getExpectedType()).thenReturn((Class)int.class); when(mockResponse.getExpectedGenericType()).thenReturn(int.class); when(mockResponse.getCharset()).thenReturn(UTF8); when(mockResponse.asStream()).thenReturn(stream); when(mockDeserializerInt.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 { Class<T> type = (Class<T>) response.getExpectedType(); isTrue(classDeserializerRegistry.contains(type), CLASS_NOT_FOUND_ERROR, type); LOG.debug("Trying to deserialize response to Type: %s.", type); return classDeserializerRegistry.get(type).<T>deserialize( type, response.getExpectedGenericType(), response.asStream(), response.getCharset()); }
ResponseDeserializerByClass implements ResponseDeserializer { public <T> T deserialize(Response response) throws Exception { Class<T> type = (Class<T>) response.getExpectedType(); isTrue(classDeserializerRegistry.contains(type), CLASS_NOT_FOUND_ERROR, type); LOG.debug("Trying to deserialize response to Type: %s.", type); return classDeserializerRegistry.get(type).<T>deserialize( type, response.getExpectedGenericType(), response.asStream(), response.getCharset()); } }
ResponseDeserializerByClass implements ResponseDeserializer { public <T> T deserialize(Response response) throws Exception { Class<T> type = (Class<T>) response.getExpectedType(); isTrue(classDeserializerRegistry.contains(type), CLASS_NOT_FOUND_ERROR, type); LOG.debug("Trying to deserialize response to Type: %s.", type); return classDeserializerRegistry.get(type).<T>deserialize( type, response.getExpectedGenericType(), response.asStream(), response.getCharset()); } ResponseDeserializerByClass(ComponentRegistry<Class<?>, Deserializer> classDeserializerRegistry); }
ResponseDeserializerByClass implements ResponseDeserializer { public <T> T deserialize(Response response) throws Exception { Class<T> type = (Class<T>) response.getExpectedType(); isTrue(classDeserializerRegistry.contains(type), CLASS_NOT_FOUND_ERROR, type); LOG.debug("Trying to deserialize response to Type: %s.", type); return classDeserializerRegistry.get(type).<T>deserialize( type, response.getExpectedGenericType(), response.asStream(), response.getCharset()); } ResponseDeserializerByClass(ComponentRegistry<Class<?>, Deserializer> classDeserializerRegistry); T deserialize(Response response); }
ResponseDeserializerByClass implements ResponseDeserializer { public <T> T deserialize(Response response) throws Exception { Class<T> type = (Class<T>) response.getExpectedType(); isTrue(classDeserializerRegistry.contains(type), CLASS_NOT_FOUND_ERROR, type); LOG.debug("Trying to deserialize response to Type: %s.", type); return classDeserializerRegistry.get(type).<T>deserialize( type, response.getExpectedGenericType(), response.asStream(), response.getCharset()); } ResponseDeserializerByClass(ComponentRegistry<Class<?>, Deserializer> classDeserializerRegistry); T deserialize(Response response);  }