@@ -4,6 +4,7 @@ import com.amazonaws.services.lambda.runtime.Context
4
4
import com.amazonaws.services.lambda.runtime.RequestHandler
5
5
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent
6
6
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
7
+ import com.fasterxml.jackson.databind.type.TypeFactory
7
8
import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException
8
9
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
9
10
import com.github.mduesterhoeft.router.ProtoBufUtils.toJsonWithoutWrappers
@@ -13,6 +14,7 @@ import org.slf4j.Logger
13
14
import org.slf4j.LoggerFactory
14
15
import java.util.Base64
15
16
import kotlin.reflect.KClass
17
+ import kotlin.reflect.full.isSubclassOf
16
18
import kotlin.reflect.jvm.reflect
17
19
18
20
abstract class RequestHandler : RequestHandler <APIGatewayProxyRequestEvent , APIGatewayProxyResponseEvent > {
@@ -55,9 +57,14 @@ abstract class RequestHandler : RequestHandler<APIGatewayProxyRequestEvent, APIG
55
57
input : APIGatewayProxyRequestEvent
56
58
): Any {
57
59
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
+ }
61
68
else -> objectMapper.readValue(input.body, requestType.java)
62
69
}
63
70
}
@@ -132,7 +139,6 @@ abstract class RequestHandler : RequestHandler<APIGatewayProxyRequestEvent, APIG
132
139
.withHeaders(mapOf (" Content-Type" to " application/json" ))
133
140
}
134
141
135
-
136
142
open fun <T > createResponse (input : APIGatewayProxyRequestEvent , response : ResponseEntity <T >): APIGatewayProxyResponseEvent {
137
143
val accept = MediaType .parse(input.acceptHeader())
138
144
return when {
0 commit comments