title: How to convert JMSBytesMessage to TextMessage in Java
body: <p>I'm build some MQ Queue Connection, I need to cast message queue to JMS Textmessage from <code>queueReceiver.Receivenowait()</code>.</p>
  
  <p>Because <code>queueReceiver.Receivenowait()</code> format is Byte, I need convert it to Textmessage for break message into array List.</p>
  
  <p>I already do this using:</p>
  
  <pre><code>queueReceiver = queueSession.createReceiver(ringQueue);
  </code></pre>
  
  <p>To get Bytemessage, I need to convert to JMS text message:</p>
  
  <pre><code>List&lt;String&gt; outputList = new ArrayList&lt;String&gt;();
  while (loop) {
     TextMessage msgResponse = (TextMessage) bytesMessage;
     if (msgResponse.getText() == null) {
        loop = false;
     } else {
        message = msgResponse.getText();
        outputList.add(message);
        msgResponse.acknowledge();
     }
  }
  </code></pre>
  
  <p>And I've got this error code: </p>
  
  <pre><code>java.lang.ClassCastException: com.ibm.jms.JMSBytesMessage cannot be cast to javax.jms.TextMessage
  </code></pre>