Class ProtobufJsonEncoder
java.lang.Object
org.springframework.http.codec.protobuf.ProtobufJsonEncoder
- All Implemented Interfaces:
org.springframework.core.codec.Encoder<com.google.protobuf.Message>
,HttpMessageEncoder<com.google.protobuf.Message>
public class ProtobufJsonEncoder
extends Object
implements HttpMessageEncoder<com.google.protobuf.Message>
A
Encoder
that writes Message
s as JSON.
To generate Message
Java classes, you need to install the
protoc
binary.
This encoder requires Protobuf 3.29 or higher, and supports
"application/json"
and "application/*+json"
with
the official "com.google.protobuf:protobuf-java-util"
library.
- Since:
- 6.2
- Author:
- Brian Clozel
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a newProtobufJsonEncoder
using a defaultJsonFormat.Printer
instance.ProtobufJsonEncoder
(com.google.protobuf.util.JsonFormat.Printer printer) Construct a newProtobufJsonEncoder
using the givenJsonFormat.Printer
instance. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canEncode
(org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType) reactor.core.publisher.Flux
<org.springframework.core.io.buffer.DataBuffer> encode
(Publisher<? extends com.google.protobuf.Message> inputStream, org.springframework.core.io.buffer.DataBufferFactory bufferFactory, org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) org.springframework.core.io.buffer.DataBuffer
encodeValue
(com.google.protobuf.Message message, org.springframework.core.io.buffer.DataBufferFactory bufferFactory, org.springframework.core.ResolvableType valueType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) List
<org.springframework.util.MimeType> Return "streaming" media types for which flushing should be performed automatically vs at the end of the input stream.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.core.codec.Encoder
getEncodableMimeTypes
Methods inherited from interface org.springframework.http.codec.HttpMessageEncoder
getEncodeHints
-
Constructor Details
-
ProtobufJsonEncoder
public ProtobufJsonEncoder()Construct a newProtobufJsonEncoder
using a defaultJsonFormat.Printer
instance. -
ProtobufJsonEncoder
public ProtobufJsonEncoder(com.google.protobuf.util.JsonFormat.Printer printer) Construct a newProtobufJsonEncoder
using the givenJsonFormat.Printer
instance.
-
-
Method Details
-
getStreamingMediaTypes
Description copied from interface:HttpMessageEncoder
Return "streaming" media types for which flushing should be performed automatically vs at the end of the input stream.- Specified by:
getStreamingMediaTypes
in interfaceHttpMessageEncoder<com.google.protobuf.Message>
-
getEncodableMimeTypes
- Specified by:
getEncodableMimeTypes
in interfaceorg.springframework.core.codec.Encoder<com.google.protobuf.Message>
-
canEncode
public boolean canEncode(org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType) - Specified by:
canEncode
in interfaceorg.springframework.core.codec.Encoder<com.google.protobuf.Message>
-
encode
public reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer> encode(Publisher<? extends com.google.protobuf.Message> inputStream, org.springframework.core.io.buffer.DataBufferFactory bufferFactory, org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) - Specified by:
encode
in interfaceorg.springframework.core.codec.Encoder<com.google.protobuf.Message>
-
encodeValue
public org.springframework.core.io.buffer.DataBuffer encodeValue(com.google.protobuf.Message message, org.springframework.core.io.buffer.DataBufferFactory bufferFactory, org.springframework.core.ResolvableType valueType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) - Specified by:
encodeValue
in interfaceorg.springframework.core.codec.Encoder<com.google.protobuf.Message>
-