code: def dumps(messages):
      
      serialized_messages = []
      try:
          for message in messages:
              message_dict = message._dump()
              serialized_messages.append(message_dict)
      except AttributeError:
          _log.error("Improper object for messages serialization.")
          raise TypeError("Message have to be instance of Message class or subclass.")
  
      return json.dumps(serialized_messages, sort_keys=True)
docs: Serialize messages to a JSON formatted str
  
      Args:
          messages (list): The list of messages to serialize. Each message in
              the messages is subclass of Messge.
  
      Returns:
          str: Serialized messages.
  
      Raises:
          TypeError: If at least one message is not instance of Message class or subclass.