diff --git a/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoBufUtils.kt b/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoBufUtils.kt index db1882a7..e07ecf63 100644 --- a/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoBufUtils.kt +++ b/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoBufUtils.kt @@ -15,7 +15,7 @@ object ProtoBufUtils { fun removeWrapperObjects(json: String): String { return removeWrapperObjects( - jacksonObjectMapper().readTree(json) + jacksonObjectMapper().readTree(json), ).toString() } @@ -38,7 +38,7 @@ object ProtoBufUtils { if (entry.value.size() > 0) { result.replace( entry.key, - removeWrapperObjects(entry.value) + removeWrapperObjects(entry.value), ) } } else { diff --git a/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoDeserializationHandler.kt b/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoDeserializationHandler.kt index db88cfc8..36a163aa 100644 --- a/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoDeserializationHandler.kt +++ b/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoDeserializationHandler.kt @@ -22,7 +22,10 @@ class ProtoDeserializationHandler : DeserializationHandler { MediaType.parse(input.contentType()).let { proto.isCompatibleWith(it) || protoStructuredSuffixWildcard.isCompatibleWith(it) } } - override fun deserialize(input: APIGatewayProxyRequestEvent, target: KType?): Any { + override fun deserialize( + input: APIGatewayProxyRequestEvent, + target: KType?, + ): Any { val bytes = Base64.getDecoder().decode(input.body) val parser = (target?.classifier as KClass<*>).staticFunctions.first { it.name == "parser" }.call() as Parser<*> return parser.parseFrom(bytes) diff --git a/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoEnabledRequestHandler.kt b/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoEnabledRequestHandler.kt index c6d3e01a..56c38342 100644 --- a/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoEnabledRequestHandler.kt +++ b/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoEnabledRequestHandler.kt @@ -6,16 +6,13 @@ import io.moia.router.RequestHandler import io.moia.router.ResponseEntity abstract class ProtoEnabledRequestHandler : RequestHandler() { + override fun serializationHandlers() = listOf(ProtoSerializationHandler()) + super.serializationHandlers() - override fun serializationHandlers() = - listOf(ProtoSerializationHandler()) + super.serializationHandlers() - - override fun deserializationHandlers() = - listOf(ProtoDeserializationHandler()) + super.deserializationHandlers() + override fun deserializationHandlers() = listOf(ProtoDeserializationHandler()) + super.deserializationHandlers() override fun createResponse( contentType: MediaType, - response: ResponseEntity + response: ResponseEntity, ): APIGatewayProxyResponseEvent { return super.createResponse(contentType, response).withIsBase64Encoded(true) } diff --git a/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoSerializationHandler.kt b/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoSerializationHandler.kt index e4b150a6..e6fd932c 100644 --- a/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoSerializationHandler.kt +++ b/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoSerializationHandler.kt @@ -7,14 +7,18 @@ import isCompatibleWith import java.util.Base64 class ProtoSerializationHandler : SerializationHandler { - private val json = MediaType.parse("application/json") private val jsonStructuredSuffixWildcard = MediaType.parse("application/*+json") - override fun supports(acceptHeader: MediaType, body: Any): Boolean = - body is GeneratedMessageV3 + override fun supports( + acceptHeader: MediaType, + body: Any, + ): Boolean = body is GeneratedMessageV3 - override fun serialize(acceptHeader: MediaType, body: Any): String { + override fun serialize( + acceptHeader: MediaType, + body: Any, + ): String { val message = body as GeneratedMessageV3 return if (json.isCompatibleWith(acceptHeader) || jsonStructuredSuffixWildcard.isCompatibleWith(acceptHeader)) { ProtoBufUtils.toJsonWithoutWrappers(message)