Class ProtobufHttpMessageConverter

java.lang.Object
org.springframework.http.converter.AbstractHttpMessageConverter<com.google.protobuf.Message>
org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter
All Implemented Interfaces:
HttpMessageConverter<com.google.protobuf.Message>
Direct Known Subclasses:
ProtobufJsonFormatHttpMessageConverter

public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter<com.google.protobuf.Message>
An 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", "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.

Since:
4.1
Author:
Alex Antonov, Brian Clozel, Juergen Hoeller, Sebastien Deleuze, Kamil Doroszkiewicz
See Also:
  • Field Details

    • DEFAULT_CHARSET

      public static final Charset DEFAULT_CHARSET
      The default charset used by the converter.
    • PROTOBUF

      public static final MediaType PROTOBUF
      The media-type for protobuf application/x-protobuf.
    • PLUS_PROTOBUF

      public static final MediaType PLUS_PROTOBUF
      The media-type for protobuf application/*+x-protobuf.
    • X_PROTOBUF_SCHEMA_HEADER

      public static final String X_PROTOBUF_SCHEMA_HEADER
      The HTTP header containing the protobuf schema.
      See Also:
    • X_PROTOBUF_MESSAGE_HEADER

      public static final String X_PROTOBUF_MESSAGE_HEADER
      The HTTP header containing the protobuf message.
      See Also:
  • Constructor Details

    • ProtobufHttpMessageConverter

      public ProtobufHttpMessageConverter()
      Construct a new ProtobufHttpMessageConverter.
    • ProtobufHttpMessageConverter

      public ProtobufHttpMessageConverter(com.google.protobuf.ExtensionRegistry extensionRegistry)
      Construct a new ProtobufHttpMessageConverter with a registry that specifies protocol message extensions.
      Parameters:
      extensionRegistry - the registry to populate
    • ProtobufHttpMessageConverter

      protected ProtobufHttpMessageConverter(@Nullable ProtobufHttpMessageConverter.ProtobufFormatDelegate formatDelegate, @Nullable com.google.protobuf.ExtensionRegistry extensionRegistry)
      Constructor for a subclass that supports additional formats.
      Parameters:
      formatDelegate - delegate to read and write additional formats
      extensionRegistry - the registry to populate
  • Method Details