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 SummaryFieldsModifier and TypeFieldDescriptionstatic final CharsetThe default charset used by the converter.static final MimeTypeThe mime-type for protobufapplication/x-protobuf.Fields inherited from class org.springframework.messaging.converter.AbstractMessageConverterlogger
- 
Constructor SummaryConstructorsConstructorDescriptionConstructor with a default instance ofExtensionRegistry.ProtobufMessageConverter(com.google.protobuf.ExtensionRegistry extensionRegistry) Constructor with a givenExtensionRegistry.
- 
Method SummaryModifier and TypeMethodDescriptionprotected booleancanConvertTo(Object payload, @Nullable MessageHeaders headers) protected ObjectconvertFromInternal(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) Convert the message payload from serialized form to an Object.protected ObjectconvertToInternal(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) Convert the payload object to serialized form.protected booleanWhether the given class is supported by this converter.Methods inherited from class org.springframework.messaging.converter.AbstractMessageConverteraddSupportedMimeTypes, canConvertFrom, fromMessage, fromMessage, getContentTypeResolver, getDefaultContentType, getMimeType, getSerializedPayloadClass, getSupportedMimeTypes, isStrictContentTypeMatch, setContentTypeResolver, setSerializedPayloadClass, setStrictContentTypeMatch, supportsMimeType, toMessage, toMessage
- 
Field Details- 
DEFAULT_CHARSETThe default charset used by the converter.
- 
PROTOBUFThe mime-type for protobufapplication/x-protobuf.
 
- 
- 
Constructor Details- 
ProtobufMessageConverterpublic ProtobufMessageConverter()Constructor with a default instance ofExtensionRegistry.
- 
ProtobufMessageConverterpublic ProtobufMessageConverter(com.google.protobuf.ExtensionRegistry extensionRegistry) Constructor with a givenExtensionRegistry.
 
- 
- 
Method Details- 
supportsDescription copied from class:AbstractMessageConverterWhether the given class is supported by this converter.- Specified by:
- supportsin class- AbstractMessageConverter
- Parameters:
- clazz- the class to test for support
- Returns:
- trueif supported;- falseotherwise
 
- 
canConvertTo- Overrides:
- canConvertToin class- AbstractMessageConverter
 
- 
convertFromInternalprotected Object convertFromInternal(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) Description copied from class:AbstractMessageConverterConvert the message payload from serialized form to an Object.- Overrides:
- convertFromInternalin class- AbstractMessageConverter
- Parameters:
- message- the input message
- targetClass- the target class for the conversion
- conversionHint- an extra object passed to the- MessageConverter, for example, the associated- MethodParameter(may be- null}
- Returns:
- the result of the conversion, or nullif the converter cannot perform the conversion
 
- 
convertToInternalprotected Object convertToInternal(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) Description copied from class:AbstractMessageConverterConvert the payload object to serialized form.- Overrides:
- convertToInternalin 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, for example, the associated- MethodParameter(may be- null}
- Returns:
- the resulting payload for the message, or nullif the converter cannot perform the conversion
 
 
-