Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Cannot serialize into SQSEvent- NPE on all accessors #107

Copy link
Copy link
@rickbhardwaj

Description

@rickbhardwaj
Issue body actions

I am trying to deserialize the default SQS test vent into an SQSEvent class, but a NPE is always thrown when I try to access the records. Looking through previous issues, others noted this and pointed to a case sensitivity issue in jackson. Any progress on this issue?

Here's my dependencies:

        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-lambda-java-core</artifactId>
            <version>1.2.0</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-lambda-java-events</artifactId>
            <version>2.2.7</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-sqs</artifactId>
            <version>1.11.708</version>
        </dependency>

The event:

{
  "Records": [
    {
      "messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78",
      "receiptHandle": "MessageReceiptHandle",
      "body": "Hello from SQS!",
      "attributes": {
        "ApproximateReceiveCount": "1",
        "SentTimestamp": "1523232000000",
        "SenderId": "123456789012",
        "ApproximateFirstReceiveTimestamp": "1523232000001"
      },
      "messageAttributes": {},
      "md5OfBody": "7b270e59b47ff90a553787216d55d91d",
      "eventSource": "aws:sqs",
      "eventSourceARN": "arn:{partition}:sqs:{region}:123456789012:MyQueue",
      "awsRegion": "{region}"
    }
  ]
}

The accessor code:

public class App implements RequestHandler<SQSEvent, Object> {

    public Object handleRequest(final SQSEvent input, final Context context) {

        System.out.println(input.getRecords());  //<--- this line throws the exception

        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        headers.put("X-Custom-Header", "application/json");

        return new GatewayResponse("SUCCESS", headers, 200);
    }
}

And the exception:

Running helloworld.AppTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.059 sec <<< FAILURE!
successfulResponse(helloworld.AppTest)  Time elapsed: 0.007 sec  <<< ERROR!
java.lang.NullPointerException
	at helloworld.App.handleRequest(App.java:22)
	at helloworld.AppTest.successfulResponse(AppTest.java:12)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.