Class JacksonResponseConverterFunction
- java.lang.Object
-
- com.linecorp.armeria.server.annotation.JacksonResponseConverterFunction
-
- All Implemented Interfaces:
ResponseConverterFunction
public class JacksonResponseConverterFunction extends Object implements ResponseConverterFunction
A response converter implementation which creates anHttpResponse
withcontent-type: application/json; charset=utf-8
orcontent-type: application/json-seq
. The objects published from aPublisher
orStream
would be converted into JSON Text Sequences if aProducesJsonSequences
annotation is specified on an annotated service method.
-
-
Constructor Summary
Constructors Constructor Description JacksonResponseConverterFunction()
Creates an instance with the defaultObjectMapper
.JacksonResponseConverterFunction(ObjectMapper mapper)
Creates an instance with the specifiedObjectMapper
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpResponse
convertResponse(ServiceRequestContext ctx, HttpHeaders headers, Object result, HttpHeaders trailingHeaders)
ReturnsHttpResponse
instance corresponds to the givenresult
.
-
-
-
Constructor Detail
-
JacksonResponseConverterFunction
public JacksonResponseConverterFunction()
Creates an instance with the defaultObjectMapper
.
-
JacksonResponseConverterFunction
public JacksonResponseConverterFunction(ObjectMapper mapper)
Creates an instance with the specifiedObjectMapper
.
-
-
Method Detail
-
convertResponse
public HttpResponse convertResponse(ServiceRequestContext ctx, HttpHeaders headers, @Nullable Object result, HttpHeaders trailingHeaders) throws Exception
Description copied from interface:ResponseConverterFunction
ReturnsHttpResponse
instance corresponds to the givenresult
. CallsResponseConverterFunction.fallthrough()
or throws aFallthroughException
if this converter cannot convert theresult
to theHttpResponse
.- Specified by:
convertResponse
in interfaceResponseConverterFunction
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()
The headers could be immutable, so please callHttpHeaders.toMutable()
. Please note that the additional headers set byServiceRequestContext.addAdditionalResponseHeader(AsciiString, String)
andAdditionalHeader
are not included in this headers.result
- The result of the service method.trailingHeaders
- The HTTP trailers that you might want to use to create theHttpResponse
. If the annotated method returnsHttpResult
, this trailers is the same trailers fromHttpResult.trailingHeaders()
. The trailers could be immutable, so please callHttpHeaders.toMutable()
. Please note that the additional trailers set byServiceRequestContext.addAdditionalResponseTrailer(AsciiString, String)
andAdditionalTrailer
are not included in this trailers.- Throws:
Exception
-
-