AWS-Java8-无法从START_OBJECT令牌中反序列化java.lang.String实例 [英] aws - java8 - Can not deserialize instance of java.lang.String out of START_OBJECT token

查看:431
本文介绍了AWS-Java8-无法从START_OBJECT令牌中反序列化java.lang.String实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java新手.

我已经使用Java 8进行了编译

I've compiled with java 8

javac HelloWorld.java --release 8

并将编译后的文件作为aws lambda代码上传.

and uploaded the complied file as the aws lambda code.

为什么在AWS Lambda中运行该错误?

Why am I getting the error when i run it in aws lambda?

public class HelloWorld
{
    public static void main(String[] args)
    {   
        System.out.println("Hello, World");
    }   
}

错误

An error occurred during JSON parsing: java.lang.RuntimeException
java.lang.RuntimeException: An error occurred during JSON parsing
Caused by: java.io.UncheckedIOException: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
 at [Source: lambdainternal.util.NativeMemoryAsInputStream@ae45eb6; line: 1, column: 1]
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
 at [Source: lambdainternal.util.NativeMemoryAsInputStream@ae45eb6; line: 1, column: 1]
    at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)

推荐答案

AWS Lambda提供了有限的Java运行时来执行AWS Java Lambda处理程序.由于代码在共享的多租户环境中运行,因此出于安全目的,这些限制在逻辑上很像访问文件系统等.为了执行程序,您的类应实现RequestHandler接口并实现handleRequest方法.这是官方文档中的示例

AWS Lambda provides limited Java runtime to execute AWS Java Lambda handlers. The limitations are logical like access to file system, etc for security purposes as the code runs in a shared multi-tenanted environment. In order to execute a program, your class should implement the RequestHandler interface and implement the handleRequest method. Here is the sample from the official documentation

package example;

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

public class Hello implements RequestHandler<Integer, String>{
  public String handleRequest(Integer myCount, Context context) {
    return String.valueOf(myCount);
  }
}

这篇关于AWS-Java8-无法从START_OBJECT令牌中反序列化java.lang.String实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆