### Question:
GenericMessageConverter implements MessageConverter { @Override public Message<?> toMessage(Object payload, MessageHeaders headers) { String name = payload.getClass().getName(); if (payload instanceof Collection) { if (payload instanceof List) { if (((List<?>) payload).isEmpty()) { return null; } name = getClassName(name, (List<?>) payload); } else { return null; } } try { String msg = objectMapper.writeValueAsString(payload); Msg message = new Msg(msg, name); return new GenericMessage<>(objectMapper.writeValueAsString(message)); } catch (JsonProcessingException e) { log.error("Serialisation failed", e); return null; } }  @Override Object fromMessage(Message<?> message, Class<?> targetClass); @Override Message<?> toMessage(Object payload, MessageHeaders headers);  }### Answer:
@Test public void toMessageEmptyObject() { Message<String> m = (Message<String>) genericMessageConverter.toMessage(new Object(), null); assertNull(m); }
@Test public void toMessage() { Message<String> m = (Message<String>) genericMessageConverter.toMessage(testData, null); TestData t2 = (TestData) genericMessageConverter.fromMessage(m, null); assertEquals(testData, t2); }
@Test public void toMessageSet() { assertNull( genericMessageConverter.toMessage( Collections.singleton("Foo"), RqueueMessageHeaders.emptyMessageHeaders())); }
@Test public void toMessageEmptyList() { assertNull( genericMessageConverter.toMessage( Collections.emptyList(), RqueueMessageHeaders.emptyMessageHeaders())); }