HttpMessageConverter 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" and "text/plain"
with the official "com.google.protobuf:protobuf-java" library.
The "application/json" format is also supported with the "com.google.protobuf:protobuf-java-util"
dependency. See ProtobufJsonFormatHttpMessageConverter for a configurable variant.
This converter requires Protobuf 3 or higher as of Spring Framework 6.1.
JsonFormat, ProtobufJsonFormatHttpMessageConverter
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static interface | ProtobufHttpMessageConverter.
Protobuf format support. |
| pack-priv static class | ProtobufHttpMessageConverter.
|
| Modifier and Type | Field and Description |
|---|---|
| public static final Charset | DEFAULT_CHARSET
The default charset used by the converter. |
| pack-priv final ExtensionRegistry | |
| private static final Map | |
| public static final MediaType | PROTOBUF
The media-type for protobuf |
| private final ProtobufHttpMessageConverter. | |
| private static final boolean | |
| public static final String | X_PROTOBUF_MESSAGE_HEADER
The HTTP header containing the protobuf message. |
| public static final String | X_PROTOBUF_SCHEMA_HEADER
The HTTP header containing the protobuf schema. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | ProtobufHttpMessageConverter(ExtensionRegistry
the registry to populate extensionRegistry)Construct a new |
| pack-priv | ProtobufHttpMessageConverter(ProtobufHttpMessageConverter.
|
| Modifier and Type | Method and Description |
|---|---|
| protected boolean | canWrite(MediaType
the media type to write, can be mediaType)null if not specified.
Typically the value of an Accept header.Overrides org. Returns |
| protected MediaType | getDefaultContentType(Message
the type to return the content type for message)Overrides org. Returns the default content type for the given type. |
| private Message. | getMessageBuilder(Class<? extends Message> clazz)
Create a new |
| protected Message | readInternal(Class<? extends Message>
the type of object to return clazz, HttpInputMessage the HTTP input message to read from inputMessage)Implements abstract org. Abstract template method that reads the actual object. |
| private void | setProtoHeader(HttpOutputMessage response, Message message)
Set the "X-Protobuf-*" HTTP headers when responding with a message of content type "application/x-protobuf" Note
|
| protected boolean | supports(Class<?>
the class to test for support clazz)Implements abstract org. Indicates whether the given class is supported by this converter. |
| protected boolean | supportsRepeatableWrites(Message
the object t message)Overrides org. Indicates whether this message converter can write the given object multiple times. |
| protected void | writeInternal(Message
the object to write to the output message message, HttpOutputMessage the HTTP output message to write to outputMessage)Implements abstract org. Abstract template method that writes the actual body. |
| DEFAULT_CHARSET | back to summary |
|---|---|
| public static final Charset DEFAULT_CHARSET The default charset used by the converter. | |
| extensionRegistry | back to summary |
|---|---|
| pack-priv final ExtensionRegistry extensionRegistry | |
| methodCache | back to summary |
|---|---|
| private static final Map<Class<?>, Method> methodCache | |
| PROTOBUF | back to summary |
|---|---|
| public static final MediaType PROTOBUF The media-type for protobuf | |
| protobufFormatSupport | back to summary |
|---|---|
| private final ProtobufHttpMessageConverter. | |
| protobufJsonFormatPresent | back to summary |
|---|---|
| private static final boolean protobufJsonFormatPresent | |
| X_PROTOBUF_MESSAGE_HEADER | back to summary |
|---|---|
| public static final String X_PROTOBUF_MESSAGE_HEADER The HTTP header containing the protobuf message. | |
| X_PROTOBUF_SCHEMA_HEADER | back to summary |
|---|---|
| public static final String X_PROTOBUF_SCHEMA_HEADER The HTTP header containing the protobuf schema. | |
| ProtobufHttpMessageConverter | back to summary |
|---|---|
| public ProtobufHttpMessageConverter() Construct a new | |
| ProtobufHttpMessageConverter | back to summary |
|---|---|
| public ProtobufHttpMessageConverter(ExtensionRegistry extensionRegistry) Construct a new
| |
| ProtobufHttpMessageConverter | back to summary |
|---|---|
| pack-priv ProtobufHttpMessageConverter(ProtobufHttpMessageConverter. | |
| canWrite | back to summary |
|---|---|
| protected boolean canWrite(MediaType mediaType) Overrides org. Doc from org. Returns | |
| getDefaultContentType | back to summary |
|---|---|
| protected MediaType getDefaultContentType(Message message) Overrides org. Doc from org. Returns the default content type for the given type. Called when By default, this returns the first element of the
| |
| getMessageBuilder | back to summary |
|---|---|
| private Message. Create a new This method uses a ConcurrentReferenceHashMap for caching method lookups. | |
| readInternal | back to summary |
|---|---|
| protected Message readInternal(Class<? extends Message> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException Implements abstract org. Doc from org. Abstract template method that reads the actual object. Invoked from
| |
| setProtoHeader | back to summary |
|---|---|
| private void setProtoHeader(HttpOutputMessage response, Message message) Set the "X-Protobuf-*" HTTP headers when responding with a message of content type "application/x-protobuf" Note
| |
| supports | back to summary |
|---|---|
| protected boolean supports(Class<?> clazz) Implements abstract org. Doc from org. Indicates whether the given class is supported by this converter. | |
| supportsRepeatableWrites | back to summary |
|---|---|
| protected boolean supportsRepeatableWrites(Message message) Overrides org. Doc from org. Indicates whether this message converter can write the given object multiple times. Default implementation returns | |
| writeInternal | back to summary |
|---|---|
| protected void writeInternal(Message message, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException Implements abstract org. Doc from org. Abstract template method that writes the actual body. Invoked from
| |
| Modifier and Type | Method and Description |
|---|---|
| public void | merge(InputStream input, Charset charset, MediaType contentType, ExtensionRegistry extensionRegistry, Message.
|
| public void | |
| public MediaType[] | |
| public boolean |
| merge | back to summary |
|---|---|
| public void merge(InputStream input, Charset charset, MediaType contentType, ExtensionRegistry extensionRegistry, Message. | |
| back to summary | |
|---|---|
| public void print(Message message, OutputStream output, MediaType contentType, Charset charset) throws IOException, HttpMessageConversionException | |
| supportedMediaTypes | back to summary |
|---|---|
| public MediaType[] supportedMediaTypes() | |
| supportsWriteOnly | back to summary |
|---|---|
| public boolean supportsWriteOnly(MediaType mediaType) | |
ProtobufFormatSupport implementation used when
com.google.protobuf.util.JsonFormat is available.
| Modifier and Type | Field and Description |
|---|---|
| private final JsonFormat. | |
| private final JsonFormat. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | merge(InputStream input, Charset charset, MediaType contentType, ExtensionRegistry extensionRegistry, Message.
Implements org.
|
| public void | print(Message message, OutputStream output, MediaType contentType, Charset charset)
Implements org.
|
| public MediaType[] | |
| public boolean |
| parser | back to summary |
|---|---|
| private final JsonFormat. | |
| printer | back to summary |
|---|---|
| private final JsonFormat. | |
| ProtobufJavaUtilSupport | back to summary |
|---|---|
| public ProtobufJavaUtilSupport(JsonFormat. | |
| merge | back to summary |
|---|---|
| public void merge(InputStream input, Charset charset, MediaType contentType, ExtensionRegistry extensionRegistry, Message. Implements org.
| |
| back to summary | |
|---|---|
| public void print(Message message, OutputStream output, MediaType contentType, Charset charset) throws IOException, HttpMessageConversionException Implements org.
| |
| supportedMediaTypes | back to summary |
|---|---|
public MediaType[] supportedMediaTypes()
| |
| supportsWriteOnly | back to summary |
|---|---|
public boolean supportsWriteOnly(MediaType mediaType)
| |