org.springframework.jms.support.converter

Class MappingJackson2MessageConverter

  • java.lang.Object
    • org.springframework.jms.support.converter.MappingJackson2MessageConverter
    • Field Detail

      • DEFAULT_ENCODING

        public static final java.lang.String DEFAULT_ENCODING
        The default encoding used for writing to text messages: UTF-8.
        See Also:
        Constant Field Values
    • Constructor Detail

      • MappingJackson2MessageConverter

        public MappingJackson2MessageConverter()
    • Method Detail

      • setObjectMapper

        public void setObjectMapper(ObjectMapper objectMapper)
        Specify the ObjectMapper to use instead of using the default.
      • setEncoding

        public void setEncoding(java.lang.String encoding)
        Specify the encoding to use when converting to and from text-based message body content. The default encoding will be "UTF-8".

        When reading from a a text-based message, an encoding may have been suggested through a special JMS property which will then be preferred over the encoding set on this MessageConverter instance.

        See Also:
        setEncodingPropertyName(java.lang.String)
      • setEncodingPropertyName

        public void setEncodingPropertyName(java.lang.String encodingPropertyName)
        Specify the name of the JMS message property that carries the encoding from bytes to String and back is BytesMessage is used during the conversion process.

        Default is none. Setting this property is optional; if not set, UTF-8 will be used for decoding any incoming bytes message.

        See Also:
        setEncoding(java.lang.String)
      • setTypeIdPropertyName

        public void setTypeIdPropertyName(java.lang.String typeIdPropertyName)
        Specify the name of the JMS message property that carries the type id for the contained object: either a mapped id value or a raw Java class name.

        Default is none. NOTE: This property needs to be set in order to allow for converting from an incoming message to a Java object.

        See Also:
        setTypeIdMappings(java.util.Map<java.lang.String, java.lang.Class<?>>)
      • setTypeIdMappings

        public void setTypeIdMappings(java.util.Map<java.lang.String,java.lang.Class<?>> typeIdMappings)
        Specify mappings from type ids to Java classes, if desired. This allows for synthetic ids in the type id message property, instead of transferring Java class names.

        Default is no custom mappings, i.e. transferring raw Java class names.

        Parameters:
        typeIdMappings - a Map with type id values as keys and Java classes as values
      • toMessage

        public Message toMessage(java.lang.Object object,
                                 Session session,
                                 @Nullable
                                 java.lang.Class<?> jsonView)
                          throws JMSException,
                                 MessageConversionException
        Convert a Java object to a JMS Message using the specified json view and the supplied session to create the message object.
        Parameters:
        object - the object to convert
        session - the Session to use for creating a JMS Message
        jsonView - the view to use to filter the content
        Returns:
        the JMS Message
        Throws:
        JMSException - if thrown by JMS API methods
        MessageConversionException - in case of conversion failure
        Since:
        4.3
      • mapToTextMessage

        protected TextMessage mapToTextMessage(java.lang.Object object,
                                               Session session,
                                               ObjectWriter objectWriter)
                                        throws JMSException,
                                               java.io.IOException
        Map the given object to a TextMessage.
        Parameters:
        object - the object to be mapped
        session - current JMS session
        objectWriter - the writer to use
        Returns:
        the resulting message
        Throws:
        JMSException - if thrown by JMS methods
        java.io.IOException - in case of I/O errors
        Since:
        4.3
        See Also:
        Session.createBytesMessage()
      • mapToBytesMessage

        protected BytesMessage mapToBytesMessage(java.lang.Object object,
                                                 Session session,
                                                 ObjectWriter objectWriter)
                                          throws JMSException,
                                                 java.io.IOException
        Map the given object to a BytesMessage.
        Parameters:
        object - the object to be mapped
        session - current JMS session
        objectWriter - the writer to use
        Returns:
        the resulting message
        Throws:
        JMSException - if thrown by JMS methods
        java.io.IOException - in case of I/O errors
        Since:
        4.3
        See Also:
        Session.createBytesMessage()
      • convertFromTextMessage

        protected java.lang.Object convertFromTextMessage(TextMessage message,
                                                          JavaType targetJavaType)
                                                   throws JMSException,
                                                          java.io.IOException
        Convert a TextMessage to a Java Object with the specified type.
        Parameters:
        message - the input message
        targetJavaType - the target type
        Returns:
        the message converted to an object
        Throws:
        JMSException - if thrown by JMS
        java.io.IOException - in case of I/O errors
      • convertFromBytesMessage

        protected java.lang.Object convertFromBytesMessage(BytesMessage message,
                                                           JavaType targetJavaType)
                                                    throws JMSException,
                                                           java.io.IOException
        Convert a BytesMessage to a Java Object with the specified type.
        Parameters:
        message - the input message
        targetJavaType - the target type
        Returns:
        the message converted to an object
        Throws:
        JMSException - if thrown by JMS
        java.io.IOException - in case of I/O errors
      • getSerializationView

        @Nullable
        protected java.lang.Class<?> getSerializationView(@Nullable
                                                                    java.lang.Object conversionHint)
        Determine a Jackson serialization view based on the given conversion hint.
        Parameters:
        conversionHint - the conversion hint Object as passed into the converter for the current conversion attempt
        Returns:
        the serialization view class, or null if none