AWS lamda输入数据不会反序列化

时间:2019-04-29 22:59:43

标签: java aws-lambda json-deserialization serverless

我正在使用无服务器框架来用Java编写AWS lambda函数。 我的处理程序类如下:

public class ConstructionHandler implements RequestHandler<Location, 
ApiGatewayResponse> {

    private static final Logger LOG = LogManager.getLogger(ConstructionHandler.class);

    @Override
    public ApiGatewayResponse handleRequest(Location input, Context context) {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            String locationJson = objectMapper.writeValueAsString(input);
            LOG.info("received: " + locationJson);
        } catch(Exception e) {
            LOG.error("Exception occurred here: " + e.getMessage());
            e.printStackTrace();
        }
        // do something useful
        // return response
    }

}

我的位置对象是一个简单的POJO,描述如下:

public class Location {

    private double x;

    private double y;

    public Location(double x, double y) {
        this.x = x;
        this.y = y;
    }

    public Location() {

    }

    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }

}

Lambda在我的serverless.yml中配置如下:

functions:
  construct:
    handler: com.serverless.ConstructionHandler
    events:
      - http:
         path: /construct
         method: post

在将具有以下请求正文的AWS部署到AWS之后,我使用Postman chrome插件向lambda发出了POST-Request:

{     “ x”:3.0,     “ y”:4.0 }

不幸的是,如果我去Cloudwatch,日志记录表明以下对象已反序列化:

{“ x”:0.0,“ y”:0.0}

有人知道为什么原始值会丢失吗? 预先感谢您的帮助!

0 个答案:

没有答案