org.springframework.messaging.converter

## Class GenericMessageConverter

- java.lang.Object
- - org.springframework.messaging.converter.SimpleMessageConverter
  - - org.springframework.messaging.converter.GenericMessageConverter

All Implemented Interfaces:
  MessageConverter

    public class GenericMessageConverter
    extends SimpleMessageConverter

An extension of the `SimpleMessageConverter` that uses a `ConversionService` to convert the payload of the message to the requested type.

Return `null` if the conversion service cannot convert from the payload type to the requested type.

Since:
  4.1
Author:
  Stephane Nicoll
See Also:
  `ConversionService`

### Constructor Summary

Constructors
Constructor and Description
`GenericMessageConverter()` Create a new instance with a default `ConversionService`.
`GenericMessageConverter(org.springframework.core.convert.ConversionService conversionService)` Create a new instance with the given `ConversionService`.

### Method Summary

All Methods Instance Methods Concrete Methods
`Object` `fromMessage(Message<?> message, Class<?> targetClass)` Convert the payload of a `Message` from a serialized form to a typed Object of the specified target class.

### Methods inherited from class org.springframework.messaging.converter.SimpleMessageConverter

`toMessage`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### GenericMessageConverter

    public GenericMessageConverter()

Create a new instance with a default `ConversionService`.

#### GenericMessageConverter

    public GenericMessageConverter(org.springframework.core.convert.ConversionService conversionService)

Create a new instance with the given `ConversionService`.

### Method Detail

#### fromMessage

    @Nullable
    public Object fromMessage(Message<?> message,
                                        Class<?> targetClass)

Description copied from interface: `MessageConverter`
Convert the payload of a `Message` from a serialized form to a typed Object of the specified target class. The `MessageHeaders.CONTENT_TYPE` header should indicate the MIME type to convert from.

If the converter does not support the specified media type or cannot perform the conversion, it should return `null`.

Specified by:
  `fromMessage` in interface `MessageConverter`
Overrides:
  `fromMessage` in class `SimpleMessageConverter`
Parameters:
  `message` - the input message
  `targetClass` - the target class for the conversion
Returns:
  the result of the conversion, or `null` if the converter cannot perform the conversion