@Test public void shouldDeserializeInputStreamUsingGenericTypeAndObjectMapper() throws IOException { ObjectMapper mockObjectMapper = mock(ObjectMapper.class); JavaType mockJavaType = mock(JavaType.class); Object mockResult = mock(Object.class); Type mockType = mock(Type.class); InputStream mockInputStream = toInputStream("hello"); Charset charset = Charset.forName("UTF-8"); mockStatic(JacksonFactory.class); mockStatic(TypeFactory.class); when(JacksonFactory.createObjectMapper(any(CRestConfig.class), any(Class.class))).thenReturn(mockObjectMapper); when(TypeFactory.type(any(Type.class))).thenReturn(mockJavaType); when(mockObjectMapper.readValue(any(InputStreamReader.class), any(JavaType.class))).thenReturn(mockResult); Object actual = new JacksonDeserializer(crestConfig).deserialize(null, mockType, mockInputStream, charset); ArgumentCaptor<InputStreamReader> inputStreamReader = ArgumentCaptor.forClass(InputStreamReader.class); assertEquals(mockResult, actual); verify(mockObjectMapper).readValue(inputStreamReader.capture(), eq(mockJavaType)); InputStreamReader actualInputStream = inputStreamReader.getValue(); assertEquals("UTF8", actualInputStream.getEncoding()); assertEquals("hello", IOs.toString(actualInputStream)); verifyStatic(); JacksonFactory.createObjectMapper(crestConfig, JacksonDeserializer.class); TypeFactory.type(mockType); }
public <T> T deserialize(Class<T> type, Type genericType, InputStream stream, Charset charset) throws IOException { try { return jackson.<T>readValue(new InputStreamReader(stream, charset), TypeFactory.type(genericType)); } finally { IOs.close(stream); } }
JacksonDeserializer implements Deserializer { public <T> T deserialize(Class<T> type, Type genericType, InputStream stream, Charset charset) throws IOException { try { return jackson.<T>readValue(new InputStreamReader(stream, charset), TypeFactory.type(genericType)); } finally { IOs.close(stream); } } }
JacksonDeserializer implements Deserializer { public <T> T deserialize(Class<T> type, Type genericType, InputStream stream, Charset charset) throws IOException { try { return jackson.<T>readValue(new InputStreamReader(stream, charset), TypeFactory.type(genericType)); } finally { IOs.close(stream); } } JacksonDeserializer(CRestConfig crestConfig); }
JacksonDeserializer implements Deserializer { public <T> T deserialize(Class<T> type, Type genericType, InputStream stream, Charset charset) throws IOException { try { return jackson.<T>readValue(new InputStreamReader(stream, charset), TypeFactory.type(genericType)); } finally { IOs.close(stream); } } JacksonDeserializer(CRestConfig crestConfig); T deserialize(Class<T> type, Type genericType, InputStream stream, Charset charset); }
JacksonDeserializer implements Deserializer { public <T> T deserialize(Class<T> type, Type genericType, InputStream stream, Charset charset) throws IOException { try { return jackson.<T>readValue(new InputStreamReader(stream, charset), TypeFactory.type(genericType)); } finally { IOs.close(stream); } } JacksonDeserializer(CRestConfig crestConfig); T deserialize(Class<T> type, Type genericType, InputStream stream, Charset charset); static final String OBJECT_MAPPER_PROP; static final String JACKSON_DESERIALIZER_CONFIG_PROP; }