Interface ResponseConverterFunction
- All Known Implementing Classes:
ByteArrayResponseConverterFunction
,HttpFileResponseConverterFunction
,JacksonResponseConverterFunction
,NullToNoContentResponseConverterFunction
,ObservableResponseConverterFunction
,ObservableResponseConverterFunction
,ProtobufResponseConverterFunction
,ServerSentEventResponseConverterFunction
,StringResponseConverterFunction
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Converts a
result
object to HttpResponse
. The class implementing this interface would
be specified as ResponseConverter
annotation.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionconvertResponse
(ServiceRequestContext ctx, ResponseHeaders headers, @Nullable Object result, HttpHeaders trailers) ReturnsHttpResponse
instance corresponds to the givenresult
.static <T> T
Throws aFallthroughException
in order to try to convertresult
toHttpResponse
by the next converter.isResponseStreaming
(Type returnType, @Nullable MediaType produceType) Returns whether anHttpResponse
of an annotated service should be streamed.
-
Method Details
-
isResponseStreaming
@UnstableApi @Nullable default @Nullable Boolean isResponseStreaming(Type returnType, @Nullable @Nullable MediaType produceType) Returns whether anHttpResponse
of an annotated service should be streamed.null
if this converter cannot convert theresponseType
to anHttpResponse
.true
can be returned if the response is a streaming type, or theResponseConverterFunction
has not been optimized for theresponseType
through overriding this method for backward compatibility.This method is used as a performance optimization hint. If the
returnType
andproduceType
are not a streaming response, it is recommended to returnfalse
for the better performance.Note that you should never return
false
for a streaming response. The non-streaming response is aggregated before being sent.- Parameters:
returnType
- the return type of the annotated service.produceType
- the negotiated producible media type of the annotated service.null
if the media type negotiation is not used for the service.
-
convertResponse
@CheckReturnValue HttpResponse convertResponse(ServiceRequestContext ctx, ResponseHeaders headers, @Nullable @Nullable Object result, HttpHeaders trailers) throws Exception ReturnsHttpResponse
instance corresponds to the givenresult
. Callsfallthrough()
if this converter cannot convert theresult
to theHttpResponse
.- Parameters:
headers
- The HTTP headers that you might want to use to create theHttpResponse
. The status of headers isHttpStatus.OK
by default orHttpStatus.NO_CONTENT
if the annotated method returnsvoid
, unless you specify it withStatusCode
on the method. The headers also will include aMediaType
ifServiceRequestContext.negotiatedResponseMediaType()
returns it. If the method returnsHttpResult
, this headers is the same headers fromHttpResult.headers()
Please note that the additional headers set byServiceRequestContext.mutateAdditionalResponseHeaders(Consumer)
andAdditionalHeader
are not included in this headers.result
- The result of the service method.trailers
- The HTTP trailers that you might want to use to create theHttpResponse
. If the annotated method returnsHttpResult
, this trailers is the same trailers fromHttpResult.trailers()
. Please note that the additional trailers set byServiceRequestContext.mutateAdditionalResponseTrailers(Consumer)
andAdditionalTrailer
are not included in this trailers.- Throws:
Exception
-
fallthrough
static <T> T fallthrough()Throws aFallthroughException
in order to try to convertresult
toHttpResponse
by the next converter.
-