类 ProtobufHttpMessageConverter
- java.lang.Object
- org.springframework.http.converter.AbstractHttpMessageConverter<com.google.protobuf.Message>
- org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter
- 所有已实现的接口:
HttpMessageConverter<com.google.protobuf.Message>
public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter<com.google.protobuf.Message>
AnHttpMessageConverter
that reads and writesMessage
s using Google Protocol Buffers.By default, it supports
"application/x-protobuf"
,"text/plain"
,"application/json"
,"application/xml"
, while also writing"text/html"
.To generate
Message
Java classes, you need to install theprotoc
binary.Requires Protobuf 2.6 and Protobuf Java Format 1.4, as of Spring 4.3.
- 从以下版本开始:
- 4.1
- 作者:
- Alex Antonov, Brian Clozel, Juergen Hoeller
字段概要
字段 修饰符和类型 字段 说明 static Charset
DEFAULT_CHARSET
static MediaType
PROTOBUF
static String
X_PROTOBUF_MESSAGE_HEADER
static String
X_PROTOBUF_SCHEMA_HEADER
从类继承的字段 org.springframework.http.converter.AbstractHttpMessageConverter
logger
构造器概要
构造器 构造器 说明 ProtobufHttpMessageConverter()
Construct a new instance.ProtobufHttpMessageConverter(ExtensionRegistryInitializer registryInitializer)
Construct a new instance with anExtensionRegistryInitializer
that allows the registration of message extensions.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected boolean
canWrite(MediaType mediaType)
This method overrides the parent implementation, since this HttpMessageConverter can also produceMediaType.HTML "text/html"
ContentType.protected MediaType
getDefaultContentType(com.google.protobuf.Message message)
Returns the default content type for the given type.protected com.google.protobuf.Message
readInternal(Class<? extends com.google.protobuf.Message> clazz, HttpInputMessage inputMessage)
Abstract template method that reads the actual object.protected boolean
supports(Class<?> clazz)
Indicates whether the given class is supported by this converter.protected void
writeInternal(com.google.protobuf.Message message, HttpOutputMessage outputMessage)
Abstract template method that writes the actual body.从类继承的方法 org.springframework.http.converter.AbstractHttpMessageConverter
addDefaultHeaders, canRead, canRead, canWrite, getContentLength, getDefaultCharset, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, write
字段详细资料
DEFAULT_CHARSET
public static final Charset DEFAULT_CHARSET
X_PROTOBUF_SCHEMA_HEADER
public static final String X_PROTOBUF_SCHEMA_HEADER
- 另请参阅:
- 常量字段值
X_PROTOBUF_MESSAGE_HEADER
public static final String X_PROTOBUF_MESSAGE_HEADER
- 另请参阅:
- 常量字段值
构造器详细资料
ProtobufHttpMessageConverter
public ProtobufHttpMessageConverter()
Construct a new instance.
ProtobufHttpMessageConverter
public ProtobufHttpMessageConverter(ExtensionRegistryInitializer registryInitializer)
Construct a new instance with anExtensionRegistryInitializer
that allows the registration of message extensions.
方法详细资料
supports
protected boolean supports(Class<?> clazz)
从类复制的说明:AbstractHttpMessageConverter
Indicates whether the given class is supported by this converter.- 指定者:
supports
在类中AbstractHttpMessageConverter<com.google.protobuf.Message>
- 参数:
clazz
- the class to test for support- 返回:
true
if supported;false
otherwise
getDefaultContentType
protected MediaType getDefaultContentType(com.google.protobuf.Message message)
从类复制的说明:AbstractHttpMessageConverter
Returns the default content type for the given type. Called whenAbstractHttpMessageConverter.write(T, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage)
is invoked without a specified content type parameter.By default, this returns the first element of the
supportedMediaTypes
property, if any. Can be overridden in subclasses.- 覆盖:
getDefaultContentType
在类中AbstractHttpMessageConverter<com.google.protobuf.Message>
- 参数:
message
- the type to return the content type for- 返回:
- the content type, or
null
if not known
readInternal
protected com.google.protobuf.Message readInternal(Class<? extends com.google.protobuf.Message> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException
从类复制的说明:AbstractHttpMessageConverter
Abstract template method that reads the actual object. Invoked fromAbstractHttpMessageConverter.read(java.lang.Class<? extends T>, org.springframework.http.HttpInputMessage)
.- 指定者:
readInternal
在类中AbstractHttpMessageConverter<com.google.protobuf.Message>
- 参数:
clazz
- the type of object to returninputMessage
- the HTTP input message to read from- 返回:
- the converted object
- 抛出:
IOException
- in case of I/O errorsHttpMessageNotReadableException
- in case of conversion errors
canWrite
protected boolean canWrite(MediaType mediaType)
This method overrides the parent implementation, since this HttpMessageConverter can also produceMediaType.HTML "text/html"
ContentType.- 覆盖:
canWrite
在类中AbstractHttpMessageConverter<com.google.protobuf.Message>
- 参数:
mediaType
- the media type to write, can benull
if not specified. Typically the value of anAccept
header.- 返回:
true
if the supported media types are compatible with the media type, or if the media type isnull
writeInternal
protected void writeInternal(com.google.protobuf.Message message, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException
从类复制的说明:AbstractHttpMessageConverter
Abstract template method that writes the actual body. Invoked fromAbstractHttpMessageConverter.write(T, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage)
.- 指定者:
writeInternal
在类中AbstractHttpMessageConverter<com.google.protobuf.Message>
- 参数:
message
- the object to write to the output messageoutputMessage
- the HTTP output message to write to- 抛出:
IOException
- in case of I/O errorsHttpMessageNotWritableException
- in case of conversion errors