Class ProtobufMessageConverter
java.lang.Object
org.springframework.messaging.converter.AbstractMessageConverter
org.springframework.messaging.converter.ProtobufMessageConverter
- All Implemented Interfaces:
MessageConverter
,SmartMessageConverter
- Direct Known Subclasses:
ProtobufJsonFormatMessageConverter
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
Modifier and TypeFieldDescriptionstatic final Charset
The default charset used by the converter.static final MimeType
The mime-type for protobufapplication/x-protobuf
.Fields inherited from class org.springframework.messaging.converter.AbstractMessageConverter
logger
-
Constructor Summary
ConstructorDescriptionConstructor with a default instance ofExtensionRegistry
.ProtobufMessageConverter
(com.google.protobuf.ExtensionRegistry extensionRegistry) Constructor with a givenExtensionRegistry
. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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
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
-
Field Details
-
DEFAULT_CHARSET
The default charset used by the converter. -
PROTOBUF
The mime-type for protobufapplication/x-protobuf
.
-
-
Constructor Details
-
ProtobufMessageConverter
public ProtobufMessageConverter()Constructor with a default instance ofExtensionRegistry
. -
ProtobufMessageConverter
public ProtobufMessageConverter(com.google.protobuf.ExtensionRegistry extensionRegistry) Constructor with a givenExtensionRegistry
.
-
-
Method Details
-
supports
Description copied from class:AbstractMessageConverter
Whether the given class is supported by this converter.- Specified by:
supports
in classAbstractMessageConverter
- Parameters:
clazz
- the class to test for support- Returns:
true
if supported;false
otherwise
-
canConvertTo
- Overrides:
canConvertTo
in classAbstractMessageConverter
-
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 classAbstractMessageConverter
- Parameters:
message
- the input messagetargetClass
- the target class for the conversionconversionHint
- an extra object passed to theMessageConverter
, for example, the associatedMethodParameter
(may benull
}- 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 classAbstractMessageConverter
- Parameters:
payload
- the Object to convertheaders
- optional headers for the message (may benull
)conversionHint
- an extra object passed to theMessageConverter
, for example, the associatedMethodParameter
(may benull
}- Returns:
- the resulting payload for the message, or
null
if the converter cannot perform the conversion
-