MMH DPR Digital
MMH DPR Digital

Reputation: 1

The return type is incompatible with RequestHandler<Object,String>.handleRequest(Object, Context) in JAVA

Im trying to run the below code, the classes mentioned in the source code is already defined except for authenticateUser , in the highlighted line error message "The return type is incompatible with RequestHandler<Object,String>.handleRequest(Object, Context)" is shown at the boldened code line below.

Kindly suggest how to correct this. Im trying to develop a simple user authentication system using https://aws.amazon.com/blogs/developer/building-a-serverless-developer-authentication-api-in-java-using-aws-lambda-amazon-dynamodb-and-amazon-cognito-part-1/ as reference.

package aws.java.lambda.demo;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;

public class Authenticate_User implements RequestHandler<Object,  String> {

    @Override
    ERROR FACE-->public AuthenticateUserResponse handleRequest(Object input, Context context)<--ERROR FACED {
          
        AuthenticateUserResponse authenticateUserResponse = new AuthenticateUserResponse();
        @SuppressWarnings("unchecked")
        LinkedHashMap inputHashMap = (LinkedHashMap)input;
        User user = authenticateUser(inputHashMap);
        if(user!=null){
            authenticateUserResponse.setUserId(user.getUserId());
            authenticateUserResponse.setStatus("true");
            authenticateUserResponse.setOpenIdToken(user.getOpenIdToken());
        }else{
            authenticateUserResponse.setUserId(null);
            authenticateUserResponse.setStatus("false");
            authenticateUserResponse.setOpenIdToken(null);
        }
            
        return authenticateUserResponse;
    }

}

Upvotes: 0

Views: 633

Answers (1)

Mark Sailes
Mark Sailes

Reputation: 852

You are trying to return a different type to the one in the class definition.

public class Authenticate_User implements RequestHandler<Object,  String> {

should be

public class Authenticate_User implements RequestHandler<Object,  AuthenticateUserResponse > {

Upvotes: 0

Related Questions