Top Description Fields Constructors Methods
org.springframework.http.codec.protobuf

public Class ProtobufHttpMessageWriter

extends EncoderHttpMessageWriter<Message>
Class Inheritance
Imports
java.lang.reflect.Method, java.util.HashMap, .Map, java.util.concurrent.ConcurrentMap, com.google.protobuf.Descriptors, .Message, org.reactivestreams.Publisher, reactor.core.publisher.Flux, .Mono, org.springframework.core.ResolvableType, org.springframework.core.codec.DecodingException, .Encoder, org.springframework.http.MediaType, .ReactiveHttpOutputMessage, org.springframework.http.codec.EncoderHttpMessageWriter, .HttpMessageEncoder, org.springframework.lang.Nullable, org.springframework.util.ConcurrentReferenceHashMap

HttpMessageWriter that can write a protobuf Message and adds X-Protobuf-Schema, X-Protobuf-Message headers and a delimited=true parameter is added to the content type if a flux is serialized.

For HttpMessageReader, just use new DecoderHttpMessageReader(new ProtobufDecoder()).

Author
Sebastien Deleuze
Since
5.1
See Also
ProtobufEncoder

Field Summary

Modifier and TypeField and Description
private static final ConcurrentMap<Class<?>, Method>
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
public
ProtobufHttpMessageWriter()

Create a new ProtobufHttpMessageWriter with a default ProtobufEncoder.

public
ProtobufHttpMessageWriter(Encoder<Message>
the Protobuf message encoder to use
encoder
)

Create a new ProtobufHttpMessageWriter with the given encoder.

Method Summary

Modifier and TypeMethod and Description
private static Message.Builder
getMessageBuilder(Class<?> clazz)

Create a new Message.Builder instance for the given class.

public Mono<Void>
write(Publisher<? extends Message>
the objects to write
inputStream
,
ResolvableType
the type of objects in the stream which must have been previously checked via canWrite(ResolvableType, MediaType)
elementType
,
MediaType
the content type for the write (possibly null to indicate that the default content type of the writer must be used)
mediaType
,
ReactiveHttpOutputMessage
the message to write to
message
,
Map<String, Object>
additional information about how to encode and write
hints
)

Overrides org.springframework.http.codec.EncoderHttpMessageWriter.write.

Implements org.springframework.http.codec.HttpMessageWriter.write.

Write a given stream of object to the output message.
Inherited from org.springframework.http.codec.EncoderHttpMessageWriter:
canWritegetEncodergetWritableMediaTypesgetWritableMediaTypesgetWriteHintswrite

Field Detail

methodCacheback to summary
private static final ConcurrentMap<Class<?>, Method> methodCache
X_PROTOBUF_MESSAGE_HEADERback to summary
private static final String X_PROTOBUF_MESSAGE_HEADER
X_PROTOBUF_SCHEMA_HEADERback to summary
private static final String X_PROTOBUF_SCHEMA_HEADER

Constructor Detail

ProtobufHttpMessageWriterback to summary
public ProtobufHttpMessageWriter()

Create a new ProtobufHttpMessageWriter with a default ProtobufEncoder.

ProtobufHttpMessageWriterback to summary
public ProtobufHttpMessageWriter(Encoder<Message> encoder)

Create a new ProtobufHttpMessageWriter with the given encoder.

Parameters
encoder:Encoder<Message>

the Protobuf message encoder to use

Method Detail

getMessageBuilderback to summary
private static Message.Builder getMessageBuilder(Class<?> clazz) throws Exception

Create a new Message.Builder instance for the given class.

This method uses a ConcurrentHashMap for caching method lookups.

writeback to summary
public Mono<Void> write(Publisher<? extends Message> inputStream, ResolvableType elementType, MediaType mediaType, ReactiveHttpOutputMessage message, Map<String, Object> hints)

Overrides org.springframework.http.codec.EncoderHttpMessageWriter.write.

Implements org.springframework.http.codec.HttpMessageWriter.write.

Doc from org.springframework.http.codec.HttpMessageWriter.write.

Write a given stream of object to the output message.

Parameters
inputStream:Publisher<? extends Message>

the objects to write

elementType:ResolvableType

the type of objects in the stream which must have been previously checked via canWrite(ResolvableType, MediaType)

mediaType:MediaType

the content type for the write (possibly null to indicate that the default content type of the writer must be used)

message:ReactiveHttpOutputMessage

the message to write to

hints:Map<String, Object>

additional information about how to encode and write

Returns:Mono<Void>

indicates completion or error

Annotations
@SuppressWarnings:unchecked
@Override