AWS Lambda Java: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token

For more details see: https://github.com/neil-rubens/aws-lambda-scala-api-gateway

With a new support for Java; Lambda has become a very good candidate for implementing many of the microservices (and providing a RestFul interface for them via API Gateway).  However the documentation on how to connect them is still lacking.  A key point is to implement the RequestHandler interface as described in the official docs; note that you will need to create custom Request and Response objects; using generic ones (e.g. String) would thrown an exception.

 

Exception

{
“Type”: “User”,
“message”: “Could not parse request body into json.”
}rialize instance of java.lang.String out of START_OBJECT token\n at [Source: lambdainternal.util.NativeMemoryAsInputStream@3224f60b; 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)”
]
}
}
}n.”
}

{
“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@72b6cbcc; 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@72b6cbcc; 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)”
]
}
}
}rialize instance of java.lang.String out of START_OBJECT token\n at [Source: lambdainternal.util.NativeMemoryAsInputStream@3224f60b; 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)”
]
}
}
}n.”
}

{
“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@7494e528; 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@7494e528; 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)”
]
}
}
}

 

 

 

 

About Neil Rubens

see http://ActiveIntelligence.org

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*