### Question:
JacksonMessageConverter implements MessageConverter { @Override public Message toMessage(Object object) { byte[] bytes; try { String jsonString = this.objectMapper.writeValueAsString(object); bytes = jsonString.getBytes(ENCODING); } catch (IOException e) { throw new MessageConversionException("Failed to convert Message content", e); } RabbitMessage.RabbitMessageProperties props = new RabbitMessage.RabbitMessageProperties(); props.setContentType(CONTENT_TYPE); props.setContentEncoding(ENCODING); props.setContentLength(bytes.length); return new RabbitMessage(bytes, props); } JacksonMessageConverter(ObjectMapper objectMapper); @Override AsyncQuery<T> readAsyncQuery(Message message, Class<T> bodyClass); @Override DomainEvent<T> readDomainEvent(Message message, Class<T> bodyClass); @Override Command<T> readCommand(Message message, Class<T> bodyClass); @Override T readValue(Message message, Class<T> valueClass); Command<T> readCommandStructure(Message message); @Override Message toMessage(Object object);  }### Answer:
@Test public void toMessage() { final Message message = converter.toMessage(new SampleClass("42", "Daniel", new Date())); assertThat(new String(message.getBody())).contains("42").contains("Daniel"); }
@Test public void toMessageWhenDataIsNull() throws IOException { final Message message = converter.toMessage(null); final JsonNode jsonNode = objectMapper.readTree(message.getBody()); assertThat(jsonNode.isNull()).isTrue(); }
@Test public void toMessageWhenDataIsEmpty() throws IOException { final Message message = converter.toMessage(""); final JsonNode jsonNode = objectMapper.readTree(message.getBody()); assertThat(jsonNode.asText()).isEmpty(); }