title: How to convert a JMS message received using Message Listener to domain object
body: <p>I am using:</p>
  
  <ul>
  <li>Spring 3.1.1</li>
  <li>ActiveMQ 5.6.0</li>
  </ul>
  
  <p>I have two JMS apps:</p>
  
  <ul>
  <li>App A uses JmsTemplate to send a domain object using jmsTemplate.convertAndSend(msg);</li>
  <li>App B uses Message Listener and a Message Converter is registered</li>
  </ul>
  
  <p>When the the received message is converted, null values are extracted.</p>
  
  <p>I know that this must be fairly simple but I am getting null values and I haven't find an example to see what I am doing wrong.</p>
  
  <p>Can some one explain please how this works?</p>
  
  <p><strong>Domain Object</strong></p>
  
  <pre><code>public class MyDomainObj implements Serializable {
  
  private static final long serialVersionUID = -5411260096045103654L;
  private String name;
  private String msg;
  
  public MyDomainObj() {
  
  }
  
  public MyDomainObj(String name, String msg) {
      this.name = name;
      this.msg = msg;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public String getMsg() {
      return msg;
  }
  
  public void setMsg(String msg) {
      this.msg = msg;
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>App A</strong></p>
  
  <pre><code>@Component
  public class MessageSender {
  
      @Autowired
      private JmsTemplate jmsTemplate;
  
      public MessageSender() {
  
      }
  
      public void sendMessage(MyDomainObj msg) {
          jmsTemplate.convertAndSend(msg);
      }
  }
  </code></pre>
  
  <p><strong>App B</strong></p>
  
  <pre><code>@Component
  public class MyReceiverConverter implements MessageConverter {
  
      @Override
      public Object fromMessage(Message msg) throws JMSException,
              MessageConversionException {
  
          MyDomainObj myDomainObj = new MyDomainObj(msg.getStringProperty("name"), msg.getStringProperty("msg"));
  
  
          return myDomainObj;
      }
  
      @Override
      public Message toMessage(Object msg, Session session) throws JMSException,
              MessageConversionException {
  
          ....
      }
  }
  </code></pre>