NewsSerializer implements Serializer<News> { @Override public byte[] serialize(String topic, News data) { try { return mapper.writeValueAsBytes(data); } catch (JsonProcessingException ex) { throw new SerializationException("Could not transform Object to JSON: " + ex.getMessage(), ex); } }  @Override void configure(Map<String, ?> configs, boolean isKey); @Override byte[] serialize(String topic, News data); @Override void close();  }
@Test public void testSerialize() throws Exception { NewsSerializer serializer = new NewsSerializer(); UUID uuid = UUID.randomUUID(); News news = new News(uuid, "Test Author", "Test TitleÄÖÜ", "Test test test"); byte[] bytes = serializer.serialize("", news); News reparsedNews = mapper.readValue(bytes, News.class); assertThat(reparsedNews.id, is(equalTo(news.id))); assertThat(reparsedNews.author, is(equalTo("Test Author"))); assertThat(reparsedNews.title, is(equalTo("Test TitleÄÖÜ"))); assertThat(reparsedNews.body, is(equalTo("Test test test"))); }