public class ProtobufMessageConverter extends AbstractMessageConverter
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.
| Modifier and Type | Field and Description |
|---|---|
static Charset |
DEFAULT_CHARSET
The default charset used by the converter.
|
static MimeType |
PROTOBUF
The mime-type for protobuf
application/x-protobuf. |
logger| Constructor and Description |
|---|
ProtobufMessageConverter()
Constructor with a default instance of
ExtensionRegistry. |
ProtobufMessageConverter(com.google.protobuf.ExtensionRegistry extensionRegistry)
Constructor with a given
ExtensionRegistry. |
| Modifier and Type | Method and Description |
|---|---|
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.
|
addSupportedMimeTypes, canConvertFrom, fromMessage, fromMessage, getContentTypeResolver, getDefaultContentType, getMimeType, getSerializedPayloadClass, getSupportedMimeTypes, isStrictContentTypeMatch, setContentTypeResolver, setSerializedPayloadClass, setStrictContentTypeMatch, supportsMimeType, toMessage, toMessagepublic static final Charset DEFAULT_CHARSET
public static final MimeType PROTOBUF
application/x-protobuf.public ProtobufMessageConverter()
ExtensionRegistry.public ProtobufMessageConverter(com.google.protobuf.ExtensionRegistry extensionRegistry)
ExtensionRegistry.protected boolean supports(Class<?> clazz)
AbstractMessageConvertersupports in class AbstractMessageConverterclazz - the class to test for supporttrue if supported; false otherwiseprotected boolean canConvertTo(Object payload, @Nullable MessageHeaders headers)
canConvertTo in class AbstractMessageConverterprotected Object convertFromInternal(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint)
AbstractMessageConverterconvertFromInternal in class AbstractMessageConvertermessage - the input messagetargetClass - the target class for the conversionconversionHint - an extra object passed to the MessageConverter,
e.g. the associated MethodParameter (may be null}null if the converter cannot
perform the conversionprotected Object convertToInternal(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint)
AbstractMessageConverterconvertToInternal in class AbstractMessageConverterpayload - the Object to convertheaders - optional headers for the message (may be null)conversionHint - an extra object passed to the MessageConverter,
e.g. the associated MethodParameter (may be null}null if the converter
cannot perform the conversion