AWS步骤函数与Lambda函数输入JSON解析错误

时间:2018-04-24 17:41:04

标签: java json amazon-web-services amazon-s3 aws-lambda

我有一个AWS Lambda Function为每个州调用LinkedList,我将PartETagMultipartUpload个对象从一个州传递给另一个州{...} 1}}。

不确定它是否有帮助,但这里是代码段:

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

import UploadJob;
import UploadJobParameters;

public class JobFinishHandler implements RequestHandler<ExportJobParameters, ExportJobParameters> {

    @Override
    public ExportJobParameters handleRequest(ExportJobParameters parameters, Context context) {

        UploadJob uploadJob = new UploadJob(parameters, context);
        context.getLogger().log("JobFinishHandler");
        context.getLogger().log("parameters: " + parameters.toString());
        context.getLogger().log("parameters.getPartETags().size(): " + parameters.getPartETags().size());
        context.getLogger().log(parameters.getPartETags().toString());
        context.getLogger().log("parameters.getPartETags().hashCode(): " + parameters.getPartETags().hashCode());
        uploadJob.continueS3UploadStream();
        uploadJob.jobFinish();
        uploadJob.jobAbort();
        return parameters;
    }

}

这是州的输入:

{ "uploadId":"1234567890", "partETags":[ { "partNumber":1, "ETag":"67c335990ba21ff95db1d09a3c2c4a11" } ] }

我收到此错误:

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: No suitable constructor found for type [simple type, class com.amazonaws.services.s3.model.PartETag]: can not instantiate from JSON object (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: lambdainternal.util.NativeMemoryAsInputStream@369f73a2; line: 1, column: 458] (through reference chain: gov.osdls.exportservices.export.common.ExportJobParameters["partETags"]->java.util.ArrayList[0])
Caused by: com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class com.amazonaws.services.s3.model.PartETag]: can not instantiate from JSON object (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: lambdainternal.util.NativeMemoryAsInputStream@369f73a2; line: 1, column: 458] (through reference chain: gov.osdls.exportservices.export.common.ExportJobParameters["partETags"]->java.util.ArrayList[0])
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1106)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:296)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:133)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:245)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:217)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:25)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:520)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:95)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:258)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:125)
at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1511)
at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1102)

我检查了PartETag类以查看是否存在默认构造函数,但事实并非如此,我将覆盖此类并创建默认构造函数。但我觉得既然PartETag是亚马逊的对象,他们难道不应该已经想到这一点吗?我做错了吗?有一个更好的方法吗?

1 个答案:

答案 0 :(得分:0)

如果有人正在寻找这个问题的答案,我只是创建了一个扩展PartETag的自定义类,并在完成MultipartUpload之前转换了列表:

import com.amazonaws.services.s3.model.PartETag;
import com.amazonaws.util.json.Jackson;

public class PartETagExt extends PartETag {

    public PartETagExt() {
        super(0, "a");
    }

    public PartETagExt(PartETag partETag) {
        super(partETag.getPartNumber(), partETag.getETag());
    }

    @Override
    public String toString() {
        return Jackson.toJsonString(this);
    }
}

然后将列表转换为常规PartETag

List<PartETag> partETags = new LinkedList<PartETag>();
partETags.addAll(partETagExts);
CompleteMultipartUploadRequest compRequest = 
                new CompleteMultipartUploadRequest(bucket, key, uploadId, partETags);