Class ProtobufResponseConverterFunction
java.lang.Object
com.linecorp.armeria.server.protobuf.ProtobufResponseConverterFunction
- All Implemented Interfaces:
com.linecorp.armeria.server.annotation.ResponseConverterFunction
@UnstableApi
public final class ProtobufResponseConverterFunction
extends Object
implements com.linecorp.armeria.server.annotation.ResponseConverterFunction
A
ResponseConverterFunction which creates an HttpResponse with
content-type: application/protobuf or content-type: application/json; charset=utf-8.
If the returned object is an instance of MessageLite, the object can be converted to either
Protocol Buffers or
JSON format.
Conversion of multiple Protobuf messages
A sequence of Protocol Buffer messages can not be handled by thisResponseConverterFunction,
because Protocol Buffers wire format is not self-delimiting.
See
Streaming Multiple Messages
for more information.
However, Publisher, Stream and Iterable are supported when converting to
JSON array.
JavaScript Object Notation (JSON) Text Sequences
is also supported for Publisher, Stream.
Note that this ResponseConverterFunction is applied to an annotated service by default,
so you don't have to specify this converter explicitly unless you want to use your own JsonFormat.Printer.
The JsonFormat.printer() is used by default to format the response content.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an instance with the defaultJsonFormat.Printer.ProtobufResponseConverterFunction(JsonFormat.Printer jsonPrinter) Creates an instance with the specifiedJsonFormat.Printer. -
Method Summary
Modifier and TypeMethodDescriptioncom.linecorp.armeria.common.HttpResponseconvertResponse(com.linecorp.armeria.server.ServiceRequestContext ctx, com.linecorp.armeria.common.ResponseHeaders headers, @Nullable Object result, com.linecorp.armeria.common.HttpHeaders trailers) isResponseStreaming(Type returnType, @Nullable com.linecorp.armeria.common.MediaType produceType)
-
Constructor Details
-
ProtobufResponseConverterFunction
public ProtobufResponseConverterFunction()Creates an instance with the defaultJsonFormat.Printer. -
ProtobufResponseConverterFunction
Creates an instance with the specifiedJsonFormat.Printer.
-
-
Method Details
-
isResponseStreaming
public Boolean isResponseStreaming(Type returnType, @Nullable @Nullable com.linecorp.armeria.common.MediaType produceType) - Specified by:
isResponseStreamingin interfacecom.linecorp.armeria.server.annotation.ResponseConverterFunction
-
convertResponse
public com.linecorp.armeria.common.HttpResponse convertResponse(com.linecorp.armeria.server.ServiceRequestContext ctx, com.linecorp.armeria.common.ResponseHeaders headers, @Nullable @Nullable Object result, com.linecorp.armeria.common.HttpHeaders trailers) throws Exception - Specified by:
convertResponsein interfacecom.linecorp.armeria.server.annotation.ResponseConverterFunction- Throws:
Exception
-