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

Problem while using jackson @JsonNaming in AWS Lambda #11397

Closed
privatejava opened this issue Aug 14, 2020 · 8 comments · Fixed by #11635
Closed

Problem while using jackson @JsonNaming in AWS Lambda #11397

privatejava opened this issue Aug 14, 2020 · 8 comments · Fixed by #11635
Labels
area/amazon-lambda kind/bug Something isn't working
Milestone

Comments

@privatejava
Copy link

privatejava commented Aug 14, 2020

I am trying to implement a @JsonNaming for a class which serializes a json property blog_title by a field named blogTitle. This is the sample URL that I am trying to parse the JSON to an object.

@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
@JsonIgnoreProperties(ignoreUnknown = true)
@RegisterForReflection
public class SampleResponse {
    private String blogTitle;

    public SampleResponse() {
    }

    public String getBlogTitle() {
        return blogTitle;
    }

    public void setBlogTitle(String blogTitle) {
        this.blogTitle = blogTitle;
    }

    @Override
    public String toString() {
        return "SampleResponse{" +
            "blogTitle='" + blogTitle + '\'' +
            '}';
    }
}

Expected behavior
Normally it works correctly in quarkus:dev mode without any issue but when I deploy it in AWS Lambda (serverless) it throws an error of no default constructor.

Actual behavior

 2020-08-14 18:31:07,726 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-1) HTTP Request to /sample failed, error id: ecb4447f-4f83-4385-bd1f-bb3fd7efccc9-2: org.jboss.resteasy.spi.UnhandledException: javax.ws.rs.ProcessingException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Class com.fasterxml.jackson.databind.PropertyNamingStrategy$SnakeCaseStrategy has no default (no arg) constructor
 at [Source: (org.jboss.resteasy.specimpl.AbstractBuiltResponse$InputStreamWrapper); line: 1, column: 1]
 at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:106)
 at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:372)
 at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:216)
 at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:515)
 at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:259)
 at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:160)
 at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
 at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:163)
 at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:245)
 at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:73)
 at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:132)
 at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.access$000(VertxRequestHandler.java:37)
 at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler$1.run(VertxRequestHandler.java:94)
 at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
 at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
 at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
 at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
 at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
 at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
 at java.lang.Thread.run(Thread.java:834)
 at org.jboss.threads.JBossThread.run(JBossThread.java:479)
 at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:517)
 at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
 Caused by: javax.ws.rs.ProcessingException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Class com.fasterxml.jackson.databind.PropertyNamingStrategy$SnakeCaseStrategy has no default (no arg) constructor
 at [Source: (org.jboss.resteasy.specimpl.AbstractBuiltResponse$InputStreamWrapper); line: 1, column: 1]
 at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:251)
 at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:88)
 at org.jboss.resteasy.specimpl.AbstractBuiltResponse.readEntity(AbstractBuiltResponse.java:256)
 at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:163)
 at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:62)
 at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:151)
 at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:112)
 at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
 at com.sun.proxy.$Proxy226.getResponse(Unknown Source)
 at java.lang.reflect.Method.invoke(Method.java:566)
 at org.jboss.resteasy.microprofile.client.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:144)
 at com.sun.proxy.$Proxy227.getResponse(Unknown Source)
 at org.acme.ExampleResource.sample(ExampleResource.java:27)
 at java.lang.reflect.Method.invoke(Method.java:566)
 at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167)
 at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:130)
 at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:638)
 at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:504)
 at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:454)
 at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
 at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:456)
 at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:417)
 at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:391)
 at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:68)
 at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:488)
 ... 19 more
 Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Class com.fasterxml.jackson.databind.PropertyNamingStrategy$SnakeCaseStrategy has no default (no arg) constructor
 at [Source: (org.jboss.resteasy.specimpl.AbstractBuiltResponse$InputStreamWrapper); line: 1, column: 1]
 at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:227)
 at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:143)
 at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:414)
 at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:349)
 at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264)
 at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
 at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
 at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:491)
 at com.fasterxml.jackson.databind.ObjectReader._findRootDeserializer(ObjectReader.java:2410)
 at com.fasterxml.jackson.databind.ObjectReader._bind(ObjectReader.java:2037)
 at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1201)
 at org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider.readFrom(ResteasyJackson2Provider.java:191)
 at org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.readFrom(AbstractReaderInterceptorContext.java:101)
 at org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:80)
 at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:214)
 ... 43 more

To Reproduce
Steps to reproduce the behavior:

  1. Create a simple class which contains @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
  2. Put a dependency for Jackson
<dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
  1. Implement a simple json parsing using jackson which has a json property in snake style format i.e "blog_title"
  2. Build it for native and aws lambda support
  3. Execute the lambda function and it throws an error.

Configuration

# Add your application.properties here, if applicable.
sample/mp-rest/url=https://run.mocky.io/v3

Environment (please complete the following information):

  • Output of uname -a or ver: Linux ngm-pc 5.4.0-42-generic Add proper logging #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

  • Output of java -version: openjdk version "11.0.7" 2020-04-14
    OpenJDK Runtime Environment GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02)
    OpenJDK 64-Bit Server VM GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02, mixed mode, sharing)

  • GraalVM version (if different from Java):

  • Quarkus version or git rev: 1.7.0.Final

  • Build tool (ie. output of mvnw --version or gradlew --version): Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)

Additional context
For doing the test I have pushed the code to github and deployed to aws as well
Public URL : https://cuti3ljzn1.execute-api.ap-southeast-1.amazonaws.com/Prod/sample
Github URL: https://github.com/privatejava/test-quarkus-rest-client-jackson

Please run the repository with mvn clean package -P native and deploy to AWS for testing.

@privatejava privatejava added the kind/bug Something isn't working label Aug 14, 2020
@quarkusbot
Copy link

/cc @patriot1burke

@patriot1burke
Copy link
Contributor

Did you cut the stack trace? Looks like there should be more there. You are running with Graal right?

@patriot1burke
Copy link
Contributor

Without seeing the full stack trace, I'm guessing that PropertyNamingStrategy.SnakeCaseStrategy needs to be added as a reflection class. See here:

https://quarkus.io/guides/writing-native-applications-tips

@privatejava
Copy link
Author

privatejava commented Aug 15, 2020

@patriot1burke

Did you cut the stack trace? Looks like there should be more there. You are running with Graal right?

No I did not remove any logs those were the only logs I get. You can even try as well I have setup that repository which throws same error.

Without seeing the full stack trace, I'm guessing that PropertyNamingStrategy.SnakeCaseStrategy needs to be added as a reflection class. See here:

https://quarkus.io/guides/writing-native-applications-tips

I tried using SnakeCaseStrategy in reflection-config.json as follows but still same issue. :

[
 {
    "name" : "com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "allDeclaredFields" : true,
    "allPublicFields" : true
  }
]

@privatejava
Copy link
Author

privatejava commented Aug 15, 2020

@patriot1burke
here is again a full AWS Lambda log after using reflection-config.json

START RequestId: 2d63ab72-9e0c-4378-b6bc-168ca8c37b43 Version: LATEST
2020-08-15 18:34:39,097 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-1) HTTP Request to /sample failed, error id: 66069051-0f44-46b1-a271-a50993188fd0-3: org.jboss.resteasy.spi.UnhandledException: javax.ws.rs.ProcessingException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Class com.fasterxml.jackson.databind.PropertyNamingStrategy$SnakeCaseStrategy has no default (no arg) constructor
at [Source: (org.jboss.resteasy.specimpl.AbstractBuiltResponse$InputStreamWrapper); line: 1, column: 1]
at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:106)
at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:372)
at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:216)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:515)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:259)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:160)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:163)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:245)
at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:73)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:132)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.access$000(VertxRequestHandler.java:37)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler$1.run(VertxRequestHandler.java:94)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
at java.lang.Thread.run(Thread.java:834)
at org.jboss.threads.JBossThread.run(JBossThread.java:479)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:517)
at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
Caused by: javax.ws.rs.ProcessingException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Class com.fasterxml.jackson.databind.PropertyNamingStrategy$SnakeCaseStrategy has no default (no arg) constructor
at [Source: (org.jboss.resteasy.specimpl.AbstractBuiltResponse$InputStreamWrapper); line: 1, column: 1]
at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:251)
at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:88)
at org.jboss.resteasy.specimpl.AbstractBuiltResponse.readEntity(AbstractBuiltResponse.java:256)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:163)
at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:62)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:151)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:112)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
at com.sun.proxy.$Proxy226.getResponse(Unknown Source)
at java.lang.reflect.Method.invoke(Method.java:566)
at org.jboss.resteasy.microprofile.client.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:144)
at com.sun.proxy.$Proxy227.getResponse(Unknown Source)
at org.acme.ExampleResource.sample(ExampleResource.java:27)
at java.lang.reflect.Method.invoke(Method.java:566)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:130)
at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:638)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:504)
at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:454)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:456)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:417)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:391)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:68)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:488)
... 19 more
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Class com.fasterxml.jackson.databind.PropertyNamingStrategy$SnakeCaseStrategy has no default (no arg) constructor
at [Source: (org.jboss.resteasy.specimpl.AbstractBuiltResponse$InputStreamWrapper); line: 1, column: 1]
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:227)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:143)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:414)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:349)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:491)
at com.fasterxml.jackson.databind.ObjectReader._findRootDeserializer(ObjectReader.java:2410)
at com.fasterxml.jackson.databind.ObjectReader._bind(ObjectReader.java:2037)
at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1201)
at org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider.readFrom(ResteasyJackson2Provider.java:191)
at org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.readFrom(AbstractReaderInterceptorContext.java:101)
at org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:80)
at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:214)
... 43 more
END RequestId: 2d63ab72-9e0c-4378-b6bc-168ca8c37b43
REPORT RequestId: 2d63ab72-9e0c-4378-b6bc-168ca8c37b43 Duration: 173.00 ms Billed Duration: 200 ms Memory Size: 128 MB Max Memory Used: 101 MB

@privatejava
Copy link
Author

I just tried using $ instead of . in reflection-config.json and it worked. 🥳 Here is the actual reflection-config.json that I used.

Previous: com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy
New : com.fasterxml.jackson.databind.PropertyNamingStrategy$SnakeCaseStrategy

[
  {
    "name" : "com.fasterxml.jackson.databind.PropertyNamingStrategy$SnakeCaseStrategy",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "allDeclaredFields" : true,
    "allPublicFields" : true
  }
]

Thanks

@gsmet gsmet reopened this Aug 26, 2020
@gsmet gsmet added this to the 1.7.2.Final milestone Aug 26, 2020
@gsmet
Copy link
Member

gsmet commented Aug 26, 2020

This is something we need to fix in the Jackson extension.

@gsmet
Copy link
Member

gsmet commented Aug 26, 2020

Fixed here: #11635 .

@gsmet gsmet modified the milestones: 1.7.2.Final, 1.8.0 - master Aug 26, 2020
gastaldi pushed a commit to gastaldi/quarkus that referenced this issue Aug 26, 2020
@gsmet gsmet modified the milestones: 1.8.0 - master, 1.7.2.Final Sep 1, 2020
gsmet added a commit to gsmet/quarkus that referenced this issue Sep 1, 2020
gsmet added a commit to gsmet/quarkus that referenced this issue Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/amazon-lambda kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants