TypeIdPropertyName
is a name of a property that identifies the entity. Jackson mapper should know what entity to use when deserializing incoming JSON.
The request should look like the following:
{
"_type" : "hello.Email",
"to" : "Imran",
"from" : "dzatorsky"
}
Btw I think this is not the best solution since JMS already know what type to use (you declare it in your method). Another drawback is that you specify name of your entity and package in the messages which will hard to maintain (every change of a package or entity name will be a pain).
Here is more robust config:
@EnableJms
@Configuration
public class JmsListenerConfig implements JmsListenerConfigurer {
@Bean
public DefaultMessageHandlerMethodFactory handlerMethodFactory() {
DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
factory.setMessageConverter(messageConverter());
return factory;
}
@Bean
public MessageConverter messageConverter() {
return new MappingJackson2MessageConverter();
}
@Override
public void configureJmsListeners(JmsListenerEndpointRegistrar registrar) {
registrar.setMessageHandlerMethodFactory(handlerMethodFactory());
}
}
Also if you use Spring JmsTemplate for sending messages you could add this component to your configuration:
/**
* Used to convert JMS messages from/to JSON. Registered in Spring-JMS automatically via auto configuration
*/
@Component
public class JsonMessageConverter implements MessageConverter {
@Autowired
private ObjectMapper mapper;
/**
* Converts message to JSON. Used mostly by {@link org.springframework.jms.core.JmsTemplate}
*/
@Override
public javax.jms.Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
String json;
try {
json = mapper.writeValueAsString(object);
} catch (Exception e) {
throw new MessageConversionException("Message cannot be parsed. ", e);
}
TextMessage message = session.createTextMessage();
message.setText(json);
return message;
}
/**
* Extracts JSON payload for further processing by JacksonMapper.
*/
@Override
public Object fromMessage(javax.jms.Message message) throws JMSException, MessageConversionException {
return ((TextMessage) message).getText();
}
}
With this configuration you can skip annoying "_type" field in your messages.