2

I am following a AWS Lambda tutorial. I have created a Lambda function that takes a custom class as input and outputs another custom class. On entering the test data I am getting a JSON parse error.

public class HelloPojo implements RequestHandler<RequestClass, ResponseClass>{

@Override
public ResponseClass handleRequest(RequestClass request, Context context){
    String greetingString = String.format("Hello %s, %s.", request.firstName, request.lastName);
    return new ResponseClass(greetingString);
}
}

This is the test input { "firstName":"John", "lastName":"Doe" }. I believe AWS requires input in json format and then it parses it. The following is the custom requestclass object:

public class RequestClass {
String firstName;
String lastName;

public RequestClass(String firstName, String lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
}
public RequestClass() {
}
public String getFirstName() {
    return firstName;
}
public void setFirstName(String firstName) {
    this.firstName = firstName;
}

This is the error message:

 "errorMessage": "An error occurred during JSON parsing",
 "errorType": "java.lang.RuntimeException",
 "stackTrace": [],
 "cause": {
     "errorMessage": "org/json/simple/JSONObject",
     "errorType": "java.lang.NoClassDefFoundError",

Here is the responseClass:

public class ResponseClass {
String greetings;

public ResponseClass(String greetings) {
    this.greetings = greetings;
}    
public ResponseClass() {
}  
public String getGreetings() {
    return greetings;
}
public void setGreetings(String greetings) {
    this.greetings = greetings;
}
public String getLastName() {
    return lastName;
}
public void setLastName(String lastName) {
    this.lastName = lastName;
}
3
  • please add ` json-simple-1.1.jar` to the lib. If already exists then clean your workspace and rebuild your project. It will work fine to you. @suku Commented May 3, 2016 at 3:26
  • This was the problem! As all inputs are json, it should have been included in the lambda build library. Can you please write your comment as the answer? Commented May 3, 2016 at 4:39
  • I have added this comment as an Answer.. Commented May 3, 2016 at 5:33

1 Answer 1

3

If you see your error message that you received as a json. you will get your answer.

     "errorMessage": "org/json/simple/JSONObject",
     "errorType": "java.lang.NoClassDefFoundError",

Error Type :- NoClassDefFoundError Exception means, At runtime when a dependent jar try to link the class named org.json.simple.JSONObject. It will not found in your library.

Solution

Please add json-simple-1.1.jar to the lib. If already exists then clean your workspace and rebuild your project. It will work fine to you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.