org.springframework.messaging.converter

## Class ProtobufMessageConverter

- java.lang.Object
- - org.springframework.messaging.converter.AbstractMessageConverter
  - - org.springframework.messaging.converter.ProtobufMessageConverter

All Implemented Interfaces:
  MessageConverter, SmartMessageConverter

Direct Known Subclasses:
  ProtobufJsonFormatMessageConverter

    public class ProtobufMessageConverter
    extends AbstractMessageConverter

An `MessageConverter` that reads and writes `com.google.protobuf.Messages` using Google Protocol Buffers.

To generate `Message` Java classes, you need to install the `protoc` binary.

This converter supports by default `"application/x-protobuf"` with the official `"com.google.protobuf:protobuf-java"` library.

`"application/json"` can be supported with the official `"com.google.protobuf:protobuf-java-util"` 3.x, with 3.3 or higher recommended.

Since:
  5.2.2
Author:
  Parviz Rozikov, Rossen Stoyanchev

### Field Summary

Fields
`static Charset` `DEFAULT_CHARSET` The default charset used by the converter.
`static org.springframework.util.MimeType` `PROTOBUF` The mime-type for protobuf `application/x-protobuf`.

### Fields inherited from class org.springframework.messaging.converter.AbstractMessageConverter

`logger`

### Constructor Summary

Constructors
Constructor and Description
`ProtobufMessageConverter()` Constructor with a default instance of `ExtensionRegistry`.
`ProtobufMessageConverter(com.google.protobuf.ExtensionRegistry extensionRegistry)` Constructor with a given `ExtensionRegistry`.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected boolean` `canConvertTo(Object payload, MessageHeaders headers)`
`protected Object` `convertFromInternal(Message<?> message, Class<?> targetClass, Object conversionHint)` Convert the message payload from serialized form to an Object.
`protected Object` `convertToInternal(Object payload, MessageHeaders headers, Object conversionHint)` Convert the payload object to serialized form.
`protected boolean` `supports(Class<?> clazz)` Whether the given class is supported by this converter.

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

`addSupportedMimeTypes, canConvertFrom, fromMessage, fromMessage, getContentTypeResolver, getDefaultContentType, getMimeType, getSerializedPayloadClass, getSupportedMimeTypes, isStrictContentTypeMatch, setContentTypeResolver, setSerializedPayloadClass, setStrictContentTypeMatch, supportsMimeType, toMessage, toMessage`

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

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

### Field Detail

#### DEFAULT_CHARSET

    public static final Charset DEFAULT_CHARSET

The default charset used by the converter.

#### PROTOBUF

    public static final org.springframework.util.MimeType PROTOBUF

The mime-type for protobuf `application/x-protobuf`.

### Constructor Detail

#### ProtobufMessageConverter

    public ProtobufMessageConverter()

Constructor with a default instance of `ExtensionRegistry`.

#### ProtobufMessageConverter

    public ProtobufMessageConverter(com.google.protobuf.ExtensionRegistry extensionRegistry)

Constructor with a given `ExtensionRegistry`.

### Method Detail

#### supports

    protected boolean supports(Class<?> clazz)

Description copied from class: `AbstractMessageConverter`
Whether the given class is supported by this converter.

Specified by:
  `supports` in class `AbstractMessageConverter`
Parameters:
  `clazz` - the class to test for support
Returns:
  `true` if supported; `false` otherwise

#### canConvertTo

    protected boolean canConvertTo(Object payload,
                                   @Nullable
                                   MessageHeaders headers)

Overrides:
  `canConvertTo` in class `AbstractMessageConverter`

#### convertFromInternal

    protected Object convertFromInternal(Message<?> message,
                                         Class<?> targetClass,
                                         @Nullable
                                         Object conversionHint)

Description copied from class: `AbstractMessageConverter`
Convert the message payload from serialized form to an Object.

Overrides:
  `convertFromInternal` in class `AbstractMessageConverter`
Parameters:
  `message` - the input message
  `targetClass` - the target class for the conversion
  `conversionHint` - an extra object passed to the `MessageConverter`, e.g. the associated `MethodParameter` (may be `null`}
Returns:
  the result of the conversion, or `null` if the converter cannot perform the conversion

#### convertToInternal

    protected Object convertToInternal(Object payload,
                                       @Nullable
                                       MessageHeaders headers,
                                       @Nullable
                                       Object conversionHint)

Description copied from class: `AbstractMessageConverter`
Convert the payload object to serialized form.

Overrides:
  `convertToInternal` in class `AbstractMessageConverter`
Parameters:
  `payload` - the Object to convert
  `headers` - optional headers for the message (may be `null`)
  `conversionHint` - an extra object passed to the `MessageConverter`, e.g. the associated `MethodParameter` (may be `null`}
Returns:
  the resulting payload for the message, or `null` if the converter cannot perform the conversion