AWS Can not deserialize instance of java.lang.String out of START_OBJECT

can not deserialize instance of java.lang.string out of start_object token
cannot deserialize instance of java lang string out of start_array token
cannot deserialize instance of java lang string out of value_string token
rest template cannot deserialize instance of java util arraylist out of start_object token
cannot deserialize instance of java lang integer out of start_object token
can not deserialize instance of java util date out of start_object token
aws lambda http request java
aws lambda-java-events example

I have made a Lambda Function and I want to access it via URL with a help of the API Gateway.

I have set it all up, I have also created an application/json body mapping template in API Gateway looking like this:

{ 
    "input": "$input.params('input')",
}

And then I am triggering HTTP GET request that looks like this:

https://dmquh95ckh.execute-api.eu-west-1.amazonaws.com/prod/OtoTestFunction?input=test

My Java handler class looks like this:

public class LambdaFunctionHandler implements RequestHandler<String, String> {

    @Override
    public String handleRequest(String input, Context context) {
        context.getLogger().log("Input: " + input);
        return "Test completed."+input;
    }
}

And this is the full error message:

{
  "errorMessage": "An error occurred during JSON parsing",
  "errorType": "java.lang.RuntimeException",
  "stackTrace": [],
  "cause": {
    "errorMessage": "com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: lambdainternal.util.NativeMemoryAsInputStream@68c4039c; line: 1, column: 1]",
    "errorType": "java.io.UncheckedIOException",
    "stackTrace": [],
    "cause": {
      "errorMessage": "Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: lambdainternal.util.NativeMemoryAsInputStream@68c4039c; line: 1, column: 1]",
      "errorType": "com.fasterxml.jackson.databind.JsonMappingException",
      "stackTrace": [
        "com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)",
        "com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:835)",
        "com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:59)",
        "com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:12)",
        "com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1441)",
        "com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1047)"
      ]
    }
  }
}

This is an error message during Lambda deserialization.

Your API Gateway mapping template is sending a JSON object, but your handler is expecting a String. Either send a raw string from API Gateway, or update your handler to use a POJO corresponding to your template output.

i.e.

public class MyPojo {
   private String input;
   public String getInput() { return input; }
   public void setInput(String input) { this.input = input; }
}

See: http://docs.aws.amazon.com/lambda/latest/dg/java-programming-model-req-resp.html

AWS Lambda Java: com.fasterxml.jackson.databind , fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token. Posted on  You are trying to deserialize the element named workstationUuid from that JSON object into this setter. @JsonProperty("workstationUuid") public void setWorkstation(String workstationUUID) { This won't work directly because Jackson sees a JSON_OBJECT, not a String.

It worked for me in all the scenarios when I change the type of input argument from String to Object.

public class LambdaFunctionHandler implements RequestHandler<Object, String> {

  @Override
  public String handleRequest(Object input, Context context) {
    String data= input != null ? input.toString() : "{}";
    context.getLogger().log("Input: " + data);
    return "Test completed."+data;
  }
}

Error executing “Hello World” for AWS Lambda in Java, JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: lambdainternal.util. AWS Lambda Java: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token

I tried with Object as parameter type as well as Pojo class and it worked in certain scenarios but while making a request from browser with API gateway URL, it failed and gave exact above error. Spent at least 2-3 hours to figure out that correct Signature, which would work in most cases is below. However this is for hello world example, you would obviously customize your input as per your requirement.

public class LambdaFunctionHandler implements RequestHandler<***Map<String,Object>,***  Customer> { 
    @Override
    public Customer handleRequest(***Map<String,Object> input***, Context context) {

    }
}

Syntax to call API / Lambda from URL, JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token\n at ,"cause":{"errorMessage":"Can not  Description As the String to be desarialized contains some nested JSON represented as String, the interperter is expecting a JsonNode for the nested JSON, rather than a String. In order to remove this requirement, use plain TypeInference as offer by the framework. "Can not deserialize instance of java.lang.String out of START_OBJECT token"

what the heck is the problem here? : aws, JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: lambdainternal.util. Can not deserialize instance of java.lang.String out of START_OBJECT token It's not clear why Jackson would do this, given you have a concrete type for your parameter. This comment has been minimized.

awslabs/aws-serverless-java-container, UncheckedIOException: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token Stefano@AWS wrote: Hi James, You can map request parameters from query string, headers, and path to generate a request body for AWS Lambda. The first step is to declare your parameters (query string and headers) in the method request page.

Could not read JSON: Can not deserialize instance of java.lang , This question may already have an answer here: Can not deserialize instance of java.lang.String out of START_OBJECT token 1 answer  AWS Lambda is a way to run code without thinking about servers. But even though you may not have to think about servers, you do have to think about how you program for AWS Lambda. You see, AWS Lambda—not to be confused with Java lambdas—is a stateless runtime environment.

Comments
  • Is this happening before your Java function is called, or after? Does your "Input: " log message show up in the logs?
  • "Either send a raw string from API Gateway": how is this done? Which "template output" does the answer refer to?