@@ -4,6 +4,7 @@ import com.amazonaws.services.lambda.runtime.Context
44import com.amazonaws.services.lambda.runtime.RequestHandler
55import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent
66import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
7+ import com.fasterxml.jackson.databind.type.TypeFactory
78import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException
89import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
910import com.github.mduesterhoeft.router.ProtoBufUtils.toJsonWithoutWrappers
@@ -13,6 +14,7 @@ import org.slf4j.Logger
1314import org.slf4j.LoggerFactory
1415import java.util.Base64
1516import kotlin.reflect.KClass
17+ import kotlin.reflect.full.isSubclassOf
1618import kotlin.reflect.jvm.reflect
1719
1820abstract class RequestHandler : RequestHandler <APIGatewayProxyRequestEvent , APIGatewayProxyResponseEvent > {
@@ -55,9 +57,14 @@ abstract class RequestHandler : RequestHandler<APIGatewayProxyRequestEvent, APIG
5557 input : APIGatewayProxyRequestEvent
5658 ): Any {
5759 val requestType = handler.reflect()!! .parameters.first().type.arguments.first().type?.classifier as KClass <* >
58- return when (requestType) {
59- Unit ::class -> Unit
60- String ::class -> input.body!!
60+ return when {
61+ requestType == Unit ::class -> Unit
62+ requestType == String ::class -> input.body!!
63+ requestType.isSubclassOf(Collection ::class ) -> {
64+ val kClass = handler.reflect()!! .parameters.first().type.arguments.first().type!! .arguments.first().type!! .classifier as KClass <* >
65+ val type = TypeFactory .defaultInstance().constructParametricType(requestType.javaObjectType, kClass.javaObjectType)
66+ objectMapper.readValue(input.body, type)
67+ }
6168 else -> objectMapper.readValue(input.body, requestType.java)
6269 }
6370 }
@@ -132,7 +139,6 @@ abstract class RequestHandler : RequestHandler<APIGatewayProxyRequestEvent, APIG
132139 .withHeaders(mapOf (" Content-Type" to " application/json" ))
133140 }
134141
135-
136142 open fun <T > createResponse (input : APIGatewayProxyRequestEvent , response : ResponseEntity <T >): APIGatewayProxyResponseEvent {
137143 val accept = MediaType .parse(input.acceptHeader())
138144 return when {
0 commit comments