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 this ResponseConverterFunction, 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 Details

    • ProtobufResponseConverterFunction

      public ProtobufResponseConverterFunction()
      Creates an instance with the default JsonFormat.Printer.
    • ProtobufResponseConverterFunction

      public ProtobufResponseConverterFunction(com.google.protobuf.util.JsonFormat.Printer jsonPrinter)
      Creates an instance with the specified JsonFormat.Printer.
  • Method Details

    • isResponseStreaming

      public Boolean isResponseStreaming(Type returnType, @Nullable @Nullable com.linecorp.armeria.common.MediaType produceType)
      Specified by:
      isResponseStreaming in interface com.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:
      convertResponse in interface com.linecorp.armeria.server.annotation.ResponseConverterFunction
      Throws:
      Exception