Class AbstractJackson2MessageConverter

    • Field Detail

      • log

        protected final Log log
      • DEFAULT_CHARSET

        public static final java.nio.charset.Charset DEFAULT_CHARSET
        The charset used when converting String to/from byte[].
      • objectMapper

        protected final com.fasterxml.jackson.databind.ObjectMapper objectMapper
    • Constructor Detail

      • AbstractJackson2MessageConverter

        protected AbstractJackson2MessageConverter​(com.fasterxml.jackson.databind.ObjectMapper objectMapper,
                                                   MimeType contentType,
                                                   java.lang.String... trustedPackages)
        Construct with the provided ObjectMapper instance.
        Parameters:
        objectMapper - the ObjectMapper to use.
        contentType - the supported content type; only the subtype is checked when decoding, e.g. */json, */xml. If this contains a charset parameter, when encoding, the contentType header will not be set, when decoding, the raw bytes are passed to Jackson which can dynamically determine the encoding; otherwise the contentEncoding or default charset is used.
        trustedPackages - the trusted Java packages for deserialization
        See Also:
        DefaultJackson2JavaTypeMapper.setTrustedPackages(String...)
    • Method Detail

      • getSupportedContentType

        protected MimeType getSupportedContentType()
        Get the supported content type; only the subtype is checked when decoding, e.g. */json, */xml. If this contains a charset parameter, when encoding, the contentType header will not be set, when decoding, the raw bytes are passed to Jackson which can dynamically determine the encoding; otherwise the contentEncoding or default charset is used.
        Returns:
        the supportedContentType
        Since:
        2.4.3
      • setSupportedContentType

        public void setSupportedContentType​(MimeType supportedContentType)
        Set the supported content type; only the subtype is checked when decoding, e.g. */json, */xml. If this contains a charset parameter, when encoding, the contentType header will not be set, when decoding, the raw bytes are passed to Jackson which can dynamically determine the encoding; otherwise the contentEncoding or default charset is used.
        Parameters:
        supportedContentType - the supportedContentType to set.
        Since:
        2.4.3
      • setNullAsOptionalEmpty

        public void setNullAsOptionalEmpty​(boolean nullAsOptionalEmpty)
        When true, if jackson decodes the body as null convert to Optional.empty() instead of returning the original body. Default false.
        Parameters:
        nullAsOptionalEmpty - true to return empty.
        Since:
        2.4.7
      • setClassMapper

        public void setClassMapper​(ClassMapper classMapper)
      • setDefaultCharset

        public void setDefaultCharset​(@Nullable
                                      java.lang.String defaultCharset)
        Specify the default charset to use when converting to or from text-based Message body content. If not specified, the charset will be "UTF-8".
        Parameters:
        defaultCharset - The default charset.
      • getDefaultCharset

        public java.lang.String getDefaultCharset()
      • getClassLoader

        protected java.lang.ClassLoader getClassLoader()
      • isTypeMapperSet

        public boolean isTypeMapperSet()
        Whether or not an explicit java type mapper has been provided.
        Returns:
        false if the default type mapper is being used.
        Since:
        2.2
        See Also:
        setJavaTypeMapper(Jackson2JavaTypeMapper)
      • setTypePrecedence

        public void setTypePrecedence​(Jackson2JavaTypeMapper.TypePrecedence typePrecedence)
        Set the precedence for evaluating type information in message properties. When using @RabbitListener at the method level, the framework attempts to determine the target type for payload conversion from the method signature. If so, this type is provided in the inferredArgumentType message property.

        By default, if the type is concrete (not abstract, not an interface), this will be used ahead of type information provided in the __TypeId__ and associated headers provided by the sender.

        If you wish to force the use of the __TypeId__ and associated headers (such as when the actual type is a subclass of the method argument type), set the precedence to Jackson2JavaTypeMapper.TypePrecedence.TYPE_ID.

        Parameters:
        typePrecedence - the precedence.
        See Also:
        DefaultJackson2JavaTypeMapper.setTypePrecedence(Jackson2JavaTypeMapper.TypePrecedence)
      • setAlwaysConvertToInferredType

        public void setAlwaysConvertToInferredType​(boolean alwaysAttemptConversion)
        When false (default), fall back to type id headers if the type (or contents of a container type) is abstract. Set to true if conversion should always be attempted - perhaps because a custom deserializer has been configured on the ObjectMapper. If the attempt fails, fall back to headers.
        Parameters:
        alwaysAttemptConversion - true to attempt.
        Since:
        2.2.8
      • isUseProjectionForInterfaces

        protected boolean isUseProjectionForInterfaces()
      • setUseProjectionForInterfaces

        public void setUseProjectionForInterfaces​(boolean useProjectionForInterfaces)
        Set to true to use Spring Data projection to create the object if the inferred parameter type is an interface.
        Parameters:
        useProjectionForInterfaces - true to use projection.
        Since:
        2.2
      • setAssumeSupportedContentType

        public void setAssumeSupportedContentType​(boolean assumeSupportedContentType)
        By default the supported content type is assumed when there is no contentType property or it is set to the default ('application/octet-stream'). Set to 'false' to revert to the previous behavior of returning an unconverted 'byte[]' when this condition exists.
        Parameters:
        assumeSupportedContentType - set false to not assume the content type is supported.
        Since:
        2.2