Class TextMessageTranslator

  • All Implemented Interfaces:
    MessageTranslator<TextMessage>, java.util.function.Function<Message<?>,​TextMessage>

    public class TextMessageTranslator
    extends java.lang.Object
    implements MessageTranslator<TextMessage>
    A MessageTranslator that converts messages into TextMessage.

    The Message Translator is the messaging equivalent of the Adapter pattern described in [GoF]. An adapter converts the interface of a component into a another interface so it can be used in a different context.

    MessageTranslator

    This implementation is relying on ObjectMappers.currentObjectMapper() to transform message payloads with non-String payload into a JSON payload.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TextMessage apply​(Message<?> message)
      Translates a Message into a Message with payload-type <String> and serializes the payload into a JSON String.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.function.Function

        andThen, compose
    • Constructor Detail

      • TextMessageTranslator

        public TextMessageTranslator()
    • Method Detail

      • apply

        @Nonnull
        public TextMessage apply​(@Nonnull
                                 Message<?> message)
        Translates a Message into a Message with payload-type <String> and serializes the payload into a JSON String.
        Specified by:
        apply in interface java.util.function.Function<Message<?>,​TextMessage>
        Specified by:
        apply in interface MessageTranslator<TextMessage>
        Parameters:
        message - Message<?>
        Returns:
        Message<String>