MappingJackson2MessageConverter converts application objects to and from JSON for Spring JMS. Declare it as a bean to use it instead of the default SimpleMessageConverter, which requires objects sent as ObjectMessages to implement Serializable. section 9.1.2
@Bean
public MappingJackson2MessageConverter messageConverter() {
MappingJackson2MessageConverter messageConverter =
new MappingJackson2MessageConverter();
messageConverter.setTypeIdPropertyName("_typeId");
return messageConverter;
}
Set a type-ID property so a receiver can identify the class to convert an incoming message into. section 9.1.2
@Bean
public MappingJackson2MessageConverter messageConverter() {
MappingJackson2MessageConverter messageConverter =
new MappingJackson2MessageConverter();
messageConverter.setTypeIdPropertyName("_typeId");
Map<String, Class<?>> typeIdMappings = new HashMap<String, Class<?>>();
typeIdMappings.put("order", TacoOrder.class);
messageConverter.setTypeIdMappings(typeIdMappings);
return messageConverter;
}
Map a short type ID such as `order` to `TacoOrder` when sender and receiver should not depend on the same fully qualified class name. section 9.1.2
With the converter configured, `JmsTemplate.convertAndSend()` can send an order object without manually creating a JMS message. section 9.1.2
