JacksonSerializer implements Serializer<T> { @Override public RawJsonDocument call(final T bean) { try { final ObjectWriter writer = mapper.writerFor(reference); final String json = writer.writeValueAsString(new BeanWrapper<T>(bean)); final String unwrapped = json.substring(START_OBJECT.length(), json.length() - END_OBJECT.length()); return RawJsonDocument.create(bean.getId(), unwrapped); } catch (final IOException e) { throw new JacksonConversionException("Error while serializing bean=" + bean, e); } }  @Override RawJsonDocument call(final T bean);  }
@Test(expected = JacksonConversionException.class) public void shouldNotSerialize() throws IOException { doThrow(JsonProcessingException.class).when(writer).writeValueAsString(any()); final RawJsonDocument single = serializer.call(entity); assertNotNull(single); }
@Test public void shouldSerialize() throws IOException { final RawJsonDocument serialized = serializer.call(entity); assertEquals(RawJsonDocument.class, serialized.getClass()); verify(mapper).writerFor(reference); verify(writer).writeValueAsString(any()); }