protected ActiveMQObjectMessage createObjectMessage(HierarchicalStreamReader in)
     throws JMSException {
   ActiveMQObjectMessage objMsg = new ActiveMQObjectMessage();
   Object obj = getXStream().unmarshal(in);
   objMsg.setObject((Serializable) obj);
   return objMsg;
 }
  @Override
  public StompFrame convertMessage(ProtocolConverter converter, ActiveMQMessage message)
      throws IOException, JMSException {

    StompFrame command = new StompFrame();
    command.setAction(Responses.MESSAGE);
    Map<String, String> headers = new HashMap<String, String>(25);
    command.setHeaders(headers);

    copyStandardHeadersFromMessageToFrame(converter, message, command, this);

    String transformation = headers.get(Headers.TRANSFORMATION);

    if (message.getDataStructureType() == ActiveMQObjectMessage.DATA_STRUCTURE_TYPE) {

      if (Transformations.JMS_XML.equals(transformation)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_OBJECT_XML.toString());
      } else if (Transformations.JMS_JSON.equals(transformation)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_OBJECT_JSON.toString());
      }

      if (!headers.containsKey(Headers.TRANSFORMATION)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_OBJECT_XML.toString());
      }

      ActiveMQObjectMessage msg = (ActiveMQObjectMessage) message.copy();
      command.setContent(
          marshall(msg.getObject(), headers.get(Headers.TRANSFORMATION)).getBytes("UTF-8"));

    } else if (message.getDataStructureType() == ActiveMQMapMessage.DATA_STRUCTURE_TYPE) {

      if (Transformations.JMS_XML.equals(transformation)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_MAP_XML.toString());
      } else if (Transformations.JMS_JSON.equals(transformation)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_MAP_JSON.toString());
      }

      if (!headers.containsKey(Headers.TRANSFORMATION)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_MAP_XML.toString());
      }

      ActiveMQMapMessage msg = (ActiveMQMapMessage) message.copy();
      command.setContent(
          marshall((Serializable) msg.getContentMap(), headers.get(Headers.TRANSFORMATION))
              .getBytes("UTF-8"));

    } else if (message.getDataStructureType() == ActiveMQMessage.DATA_STRUCTURE_TYPE
        && AdvisorySupport.ADIVSORY_MESSAGE_TYPE.equals(message.getType())) {

      if (Transformations.JMS_XML.equals(transformation)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_ADVISORY_XML.toString());
      } else if (Transformations.JMS_JSON.equals(transformation)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_ADVISORY_JSON.toString());
      }

      if (!headers.containsKey(Headers.TRANSFORMATION)) {
        headers.put(Headers.TRANSFORMATION, Transformations.JMS_ADVISORY_JSON.toString());
      }

      String body =
          marshallAdvisory(message.getDataStructure(), headers.get(Headers.TRANSFORMATION));
      command.setContent(body.getBytes("UTF-8"));

    } else {
      command = super.convertMessage(converter, message);
    }

    return command;
  }