micronaut-projects / micronaut-aws

Projects specific to integrating Micronaut and Amazon Web Services (AWS)
Apache License 2.0
82 stars 81 forks source link

Override AWS SDK internal objectMapper with Micronaut ObjectMapper instance #2141

Open dniel opened 2 weeks ago

dniel commented 2 weeks ago

Issue description

I see that the AWS SDK has its own internal objectMapper with its own configuration, instead of the one micronaut provided.

We have a custom deserializer to handle dynamodb streams events to our lambda, and its working when we test it in unit tests and Micronaut but unfortunately its not used by AWS SDK, with its own object mapper without that configured.

Do you know if its possible to override the AWS SDK internal instance to be the Micronaut objectmapper?

thaugrud commented 2 weeks ago

We have implemented a custom deserializer for the software.amazon.awssdk.services.dynamodb.model.Record class from the AWS SDK that works as expected when read by the injected Objectmapper as shown below:

val record = objectMapper.readValue(serializedRecordString, Record::class.java)

Then we have implemented a Lambda using the class as an input parameter:

@SerdeImport(Record::class)
class Handler : MicronautRequestHandler<List<Record>, Boolean>() {
    private val logger = KotlinLogging.logger {}

    @Inject
    private lateinit var objectMapper: ObjectMapper

    override fun execute(records: List<Record>):  {
        logger.info { "Received event" }
        logger.info { "Records: $records" }

        return true
    }
}

Here we are expecting the Lambda runtime to have access to the custom Serde deserializer and deserialize the incoming data into the expected Record-class. However the application errors during parsing when attempting to parse the incoming data from JSON as it does not appear to use the Micronaut objectMapper.