Just call the JSON message converter yourself to create a TextMessage
and print it before sending; same thing on the consuming side, receive a text message, print it, and then use the converter in your code to convert to the object.
EDIT
Another alternative would be to subclass the converter and do the logging after/before conversion.
EDIT
Here's an example:
@SpringBootApplication
public class So51251864Application {
public static void main(String[] args) {
SpringApplication.run(So51251864Application.class, args);
}
@Bean
public ApplicationRunner runner(JmsTemplate template) {
return args -> template.convertAndSend("foo", new Foo("baz"));
}
@Bean
public MessageConverter converter() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter() {
@Override
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
TextMessage message = (TextMessage) super.toMessage(object, session);
System.out.println("outbound json: " + message.getText());
return message;
}
@Override
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
System.out.println("inbound json: " + ((TextMessage) message).getText());
return super.fromMessage(message);
}
};
converter.setTargetType(MessageType.TEXT);
converter.setTypeIdPropertyName("type");
return converter;
}
@JmsListener(destination = "foo")
public void listen(Foo foo) {
System.out.println(foo);
}
public static class Foo {
private String bar;
public Foo() {
super();
}
public Foo(String bar) {
this.bar = bar;
}
public String getBar() {
return this.bar;
}
public void setBar(String bar) {
this.bar = bar;
}
@Override
public String toString() {
return "Foo [bar=" + this.bar + "]";
}
}
}
and
outbound json: {"bar":"baz"}
inbound json: {"bar":"baz"}
Foo [bar=baz]