Class ProtobufRequestConverterFunction
java.lang.Object
com.linecorp.armeria.server.protobuf.ProtobufRequestConverterFunction
- All Implemented Interfaces:
RequestConverterFunction
@UnstableApi
public final class ProtobufRequestConverterFunction
extends Object
implements RequestConverterFunction
A
RequestConverterFunction
which converts a Protocol Buffers or JSON body of
the AggregatedHttpRequest
to an object.
The built-in parser of Message
for Protocol Buffers is applied only when the content-type
of
RequestHeaders
is either one of MediaType.PROTOBUF
or MediaType.OCTET_STREAM
or
the MediaType.subtype()
contains "protobuf"
.
The JsonFormat.Parser
for JSON is applied only when the content-type
of
the RequestHeaders
is either MediaType.JSON
or ends with +json
.
Conversion of multiple Protobuf messages
A sequence of Protocol Buffer messages can not be handled by thisRequestConverterFunction
,
because Protocol Buffers wire format is not self-delimiting.
See
Streaming Multiple Messages
for more information.
However, Collection
types such as List<Message>
and Set<Message>
are supported
when converted from JSON array.
Note that this RequestConverterFunction
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.Parser
and
ExtensionRegistry
.
-
Constructor Summary
ConstructorDescriptionCreates an instance with the defaultJsonFormat.Parser
andExtensionRegistry
.ProtobufRequestConverterFunction(JsonFormat.Parser jsonParser, ExtensionRegistry extensionRegistry)
Creates an instance with the specifiedJsonFormat.Parser
andExtensionRegistry
. -
Method Summary
Modifier and TypeMethodDescriptionconvertRequest(ServiceRequestContext ctx, AggregatedHttpRequest request, Class<?> expectedResultType, @Nullable ParameterizedType expectedParameterizedResultType)
Converts the specifiedrequest
to an object ofexpectedResultType
.
-
Constructor Details
-
ProtobufRequestConverterFunction
public ProtobufRequestConverterFunction()Creates an instance with the defaultJsonFormat.Parser
andExtensionRegistry
. -
ProtobufRequestConverterFunction
public ProtobufRequestConverterFunction(JsonFormat.Parser jsonParser, ExtensionRegistry extensionRegistry)Creates an instance with the specifiedJsonFormat.Parser
andExtensionRegistry
.
-
-
Method Details
-
convertRequest
@Nullable public @Nullable Object convertRequest(ServiceRequestContext ctx, AggregatedHttpRequest request, Class<?> expectedResultType, @Nullable @Nullable ParameterizedType expectedParameterizedResultType) throws ExceptionDescription copied from interface:RequestConverterFunction
Converts the specifiedrequest
to an object ofexpectedResultType
. CallsRequestConverterFunction.fallthrough()
or throws aFallthroughException
if this converter cannot convert therequest
to an object.- Specified by:
convertRequest
in interfaceRequestConverterFunction
- Parameters:
ctx
- theServiceRequestContext
ofrequest
.request
- theAggregatedHttpRequest
being handled.expectedResultType
- the desired type of the conversion result.expectedParameterizedResultType
- the desired parameterized type of the conversion result.null
will be given ifexpectedResultType
doesn't have any type parameters.- Throws:
Exception
-