GsonValueMapper implements ValueMapper { @Override public void write(Object value, OutputStream out) throws SerializerException { final byte[] bytes = gson.toJson(value).getBytes(); try { out.write(bytes); } catch (IOException e) { throw new SerializerException("Failed to write to json", e); } } GsonValueMapper(Gson gson); @Override void write(Object value, OutputStream out); @Override T read(Class<T> type, InputStream in);  }
@Test public void shouldWriteTheBytesOfObject() throws Exception { UserTestModel userTestModel = fakeUserTestObject(); final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); valueMapper.write(userTestModel, bytesOut); Assertions.assertThat(bytesOut).isNotNull(); Assertions.assertThat(bytesOut.size()).isGreaterThan(0); }