Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guides on AWS Lambda s3 event fails with micronaut 4.2.2, 4.2.3 : An error occurred during JSON parsing: java.lang.RuntimeException #1410

Open
marcpa00 opened this issue Jan 6, 2024 · 4 comments

Comments

@marcpa00
Copy link

marcpa00 commented Jan 6, 2024

Using the completed example zip (https://guides.micronaut.io/latest/micronaut-aws-lambda-s3-event-gradle-java.zip) (2024-01-06, micronaut 4.2.2) and following the instructions in https://guides.micronaut.io/latest/micronaut-aws-lambda-s3-event-gradle-java.html to create aws bucket, role, lambda function with appropriate trigger, produced the stack trace (full log in csv attached) :

An error occurred during JSON parsing: java.lang.RuntimeException
java.lang.RuntimeException: An error occurred during JSON parsing
Caused by: io.micronaut.function.aws.CustomPojoSerializerException: io.micronaut.serde.exceptions.SerdeException: Error decoding property [List records] of type [class com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification]: Cannot invoke "io.micronaut.serde.Deserializer.deserializeNullable(io.micronaut.serde.Decoder, io.micronaut.serde.Deserializer$DecoderContext, io.micronaut.core.type.Argument)" because "this.deserializer" is null
	at io.micronaut.function.aws.JsonMapperCustomPojoSerializer.fromJson(JsonMapperCustomPojoSerializer.java:72)
Caused by: io.micronaut.serde.exceptions.SerdeException: Error decoding property [List records] of type [class com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification]: Cannot invoke "io.micronaut.serde.Deserializer.deserializeNullable(io.micronaut.serde.Decoder, io.micronaut.serde.Deserializer$DecoderContext, io.micronaut.core.type.Argument)" because "this.deserializer" is null
	at io.micronaut.serde.support.deserializers.DeserBean$DerProperty.deserializeAndSetConstructorValue(DeserBean.java:857)
	at io.micronaut.serde.support.deserializers.SimpleRecordLikeObjectDeserializer.deserialize(SimpleRecordLikeObjectDeserializer.java:68)
	at io.micronaut.serde.support.deserializers.SimpleRecordLikeObjectDeserializer.deserializeNullable(SimpleRecordLikeObjectDeserializer.java:102)
	at io.micronaut.serde.jackson.JacksonJsonMapper.readValue0(JacksonJsonMapper.java:177)
	at io.micronaut.serde.jackson.JacksonJsonMapper.readValue(JacksonJsonMapper.java:169)
	at io.micronaut.serde.jackson.JacksonJsonMapper.readValue(JacksonJsonMapper.java:206)
	at io.micronaut.function.aws.JsonMapperCustomPojoSerializer.fromJson(JsonMapperCustomPojoSerializer.java:70)
Caused by: java.lang.NullPointerException: Cannot invoke "io.micronaut.serde.Deserializer.deserializeNullable(io.micronaut.serde.Decoder, io.micronaut.serde.Deserializer$DecoderContext, io.micronaut.core.type.Argument)" because "this.deserializer" is null
	at io.micronaut.serde.support.deserializers.DeserBean$DerProperty.deserializeAndSetConstructorValue(DeserBean.java:838)
	... 6 more

log-events-viewer-result.csv

@marcpa00 marcpa00 changed the title Guides on AWS Lambda s3 event fails with micronaut 4.2.3 : An error occurred during JSON parsing: java.lang.RuntimeException Guides on AWS Lambda s3 event fails with micronaut 4.2.2 : An error occurred during JSON parsing: java.lang.RuntimeException Jan 6, 2024
@marcpa00
Copy link
Author

marcpa00 commented Jan 6, 2024

Just noticed the downloaded zip uses micronaut 4.2.2; will change for 4.2.3 and report back if issue is still there.

@marcpa00
Copy link
Author

marcpa00 commented Jan 6, 2024

Verified with micronaut 4.2.3 : same outcome (but stack trace sightly different)

  • Modified gradle.properties to read
micronautVersion=4.2.3
org.gradle.jvmargs=-Xmx4G
  • rebuilt the shadow jar : ./gradlew shadowJar
  • uploaded resulting build/libs/default-0.1-all.jar as the code for the lambda function
  • uploaded a new png file in my bucket

Result is :

An error occurred during JSON parsing: java.lang.RuntimeException
java.lang.RuntimeException: An error occurred during JSON parsing
Caused by: io.micronaut.core.beans.exceptions.IntrospectionException: No deserializable introspection present for type: ResponseElementsEntity responseElements. Consider adding Serdeable.Deserializable annotate to type ResponseElementsEntity responseElements. Alternatively if you are not in control of the project's source code, you can use @SerdeImport(ResponseElementsEntity.class) to enable deserialization of this type.
	at io.micronaut.serde.support.DefaultSerdeIntrospections.resolveIntrospectionForDeserialization(DefaultSerdeIntrospections.java:196)
	at io.micronaut.serde.support.DefaultSerdeIntrospections.getDeserializableIntrospection(DefaultSerdeIntrospections.java:160)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.createDeserBean(ObjectDeserializer.java:133)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.lambda$getDeserializableBean$1(ObjectDeserializer.java:123)
	at io.micronaut.core.util.SupplierUtil$2.get(SupplierUtil.java:79)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.getDeserializableBean(ObjectDeserializer.java:124)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.createSpecific(ObjectDeserializer.java:69)
	at io.micronaut.serde.support.deserializers.DeserBean.findDeserializer(DeserBean.java:592)
	at io.micronaut.serde.support.deserializers.DeserBean.initProperty(DeserBean.java:476)
	at io.micronaut.serde.support.deserializers.DeserBean.initializeInternal(DeserBean.java:432)
	at io.micronaut.serde.support.deserializers.DeserBean.initialize(DeserBean.java:412)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.getDeserializableBean(ObjectDeserializer.java:125)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.createSpecific(ObjectDeserializer.java:69)
	at io.micronaut.serde.support.deserializers.collect.CoreCollectionsDeserializers$SpecificOnlyCollectionDeserializer.createSpecific(CoreCollectionsDeserializers.java:334)
	at io.micronaut.serde.support.deserializers.DeserBean.findDeserializer(DeserBean.java:592)
	at io.micronaut.serde.support.deserializers.DeserBean.initProperty(DeserBean.java:476)
	at io.micronaut.serde.support.deserializers.DeserBean.initializeInternal(DeserBean.java:432)
	at io.micronaut.serde.support.deserializers.DeserBean.initialize(DeserBean.java:412)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.getDeserializableBean(ObjectDeserializer.java:125)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.createSpecific(ObjectDeserializer.java:69)
	at io.micronaut.serde.jackson.JacksonJsonMapper.readValue0(JacksonJsonMapper.java:175)
	at io.micronaut.serde.jackson.JacksonJsonMapper.readValue(JacksonJsonMapper.java:169)
	at io.micronaut.serde.jackson.JacksonJsonMapper.readValue(JacksonJsonMapper.java:206)
	at io.micronaut.function.aws.JsonMapperCustomPojoSerializer.fromJson(JsonMapperCustomPojoSerializer.java:70)

@marcpa00
Copy link
Author

marcpa00 commented Jan 6, 2024

I tried to add SerdeImport annotations as suggested in stack trace to no avail.

@Serdeable
@SerdeImport(S3EventNotification.ResponseElementsEntity.class)
@SerdeImport(S3EventNotification.S3ObjectEntity.class)
public class FunctionRequestHandler
        extends MicronautRequestHandler<S3EventNotification, Void> { // <1>

Stack trace :

An error occurred during JSON parsing: java.lang.RuntimeException
java.lang.RuntimeException: An error occurred during JSON parsing
Caused by: io.micronaut.core.beans.exceptions.IntrospectionException: No deserializable introspection present for type: S3ObjectEntity object. Consider adding Serdeable.Deserializable annotate to type S3ObjectEntity object. Alternatively if you are not in control of the project's source code, you can use @SerdeImport(S3ObjectEntity.class) to enable deserialization of this type.
	at io.micronaut.serde.support.DefaultSerdeIntrospections.resolveIntrospectionForDeserialization(DefaultSerdeIntrospections.java:196)
	at io.micronaut.serde.support.DefaultSerdeIntrospections.getDeserializableIntrospection(DefaultSerdeIntrospections.java:160)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.createDeserBean(ObjectDeserializer.java:133)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.lambda$getDeserializableBean$1(ObjectDeserializer.java:123)
	at io.micronaut.core.util.SupplierUtil$2.get(SupplierUtil.java:79)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.getDeserializableBean(ObjectDeserializer.java:124)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.createSpecific(ObjectDeserializer.java:69)
	at io.micronaut.serde.support.deserializers.DeserBean.findDeserializer(DeserBean.java:592)
	at io.micronaut.serde.support.deserializers.DeserBean.initProperty(DeserBean.java:476)
	at io.micronaut.serde.support.deserializers.DeserBean.initializeInternal(DeserBean.java:432)
	at io.micronaut.serde.support.deserializers.DeserBean.initialize(DeserBean.java:412)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.getDeserializableBean(ObjectDeserializer.java:125)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.createSpecific(ObjectDeserializer.java:69)
	at io.micronaut.serde.support.deserializers.DeserBean.findDeserializer(DeserBean.java:592)
	at io.micronaut.serde.support.deserializers.DeserBean.initProperty(DeserBean.java:476)
	at io.micronaut.serde.support.deserializers.DeserBean.initializeInternal(DeserBean.java:432)
	at io.micronaut.serde.support.deserializers.DeserBean.initialize(DeserBean.java:412)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.getDeserializableBean(ObjectDeserializer.java:125)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.createSpecific(ObjectDeserializer.java:69)
	at io.micronaut.serde.support.deserializers.collect.CoreCollectionsDeserializers$SpecificOnlyCollectionDeserializer.createSpecific(CoreCollectionsDeserializers.java:334)
	at io.micronaut.serde.support.deserializers.DeserBean.findDeserializer(DeserBean.java:592)
	at io.micronaut.serde.support.deserializers.DeserBean.initProperty(DeserBean.java:476)
	at io.micronaut.serde.support.deserializers.DeserBean.initializeInternal(DeserBean.java:432)
	at io.micronaut.serde.support.deserializers.DeserBean.initialize(DeserBean.java:412)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.getDeserializableBean(ObjectDeserializer.java:125)
	at io.micronaut.serde.support.deserializers.ObjectDeserializer.createSpecific(ObjectDeserializer.java:69)
	at io.micronaut.serde.jackson.JacksonJsonMapper.readValue0(JacksonJsonMapper.java:175)
	at io.micronaut.serde.jackson.JacksonJsonMapper.readValue(JacksonJsonMapper.java:169)
	at io.micronaut.serde.jackson.JacksonJsonMapper.readValue(JacksonJsonMapper.java:206)
	at io.micronaut.function.aws.JsonMapperCustomPojoSerializer.fromJson(JsonMapperCustomPojoSerializer.java:70)


@marcpa00 marcpa00 changed the title Guides on AWS Lambda s3 event fails with micronaut 4.2.2 : An error occurred during JSON parsing: java.lang.RuntimeException Guides on AWS Lambda s3 event fails with micronaut 4.2.2, 4.2.3 : An error occurred during JSON parsing: java.lang.RuntimeException Jan 6, 2024
@marcpa00
Copy link
Author

marcpa00 commented Jan 6, 2024

Note that trying to use Jackson serialization by adding the jackson-databind dependency does not work either.

Modified dependencies in gradle.build :

dependencies {
    annotationProcessor("io.micronaut.serde:micronaut-serde-processor")
    annotationProcessor("io.micronaut.validation:micronaut-validation-processor")
    implementation("io.micronaut:micronaut-jackson-databind")
    implementation("com.amazonaws:aws-lambda-java-events")
    implementation("io.micronaut.aws:micronaut-aws-lambda-events-serde")
    implementation("io.micronaut.aws:micronaut-aws-sdk-v2")
    implementation("io.micronaut.aws:micronaut-function-aws")
    implementation("io.micronaut.crac:micronaut-crac")
    implementation("io.micronaut.validation:micronaut-validation")
    implementation("jakarta.validation:jakarta.validation-api")
    implementation("net.coobird:thumbnailator:0.4.17")
    implementation("software.amazon.awssdk:s3:2.17.277")
    runtimeOnly("ch.qos.logback:logback-classic")
    runtimeOnly("org.yaml:snakeyaml")
}

Result:

An error occurred during JSON parsing: java.lang.RuntimeException
java.lang.RuntimeException: An error occurred during JSON parsing
Caused by: io.micronaut.function.aws.CustomPojoSerializerException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
 at [Source: (ByteArrayInputStream); line: 1, column: 2]
	at io.micronaut.function.aws.JsonMapperCustomPojoSerializer.fromJson(JsonMapperCustomPojoSerializer.java:72)
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
 at [Source: (ByteArrayInputStream); line: 1, column: 2]
	at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
	at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1915)
	at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:414)
	at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1360)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1424)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:352)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:185)
	at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:323)
	at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:2105)
	at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1481)
	at io.micronaut.jackson.databind.JacksonDatabindMapper.readValue(JacksonDatabindMapper.java:168)
	at io.micronaut.function.aws.JsonMapperCustomPojoSerializer.fromJson(JsonMapperCustomPojoSerializer.java:70)


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant