AWS,Lambda,Java,POJO,自定义json属性名称

gle*_*sts 5 java json pojo amazon-web-services aws-lambda

使用Lambda进行首次尝试.创建代码,部署,测试工作,但是:

public String handleRequest(MyType inObj, Context context) {
    // logging inObj here
}
Run Code Online (Sandbox Code Playgroud)

POJO课程

public class MyType {
    String prop;
    String otherProp;
}
Run Code Online (Sandbox Code Playgroud)

在调用时,我给出了以下有效负载:

{ "prop": "val1", "other_prop": "val2" }
Run Code Online (Sandbox Code Playgroud)

如你所见,我想在snake_case中给json.当lambda记录时,我可以看到

inObj.prop =="val1"

inObj.otherProp =="null".

当我将jSON从snake_case更改为camelCase时,它被正确地反序列化并且otherProp =="val2".我尝试将@JsonProperty("other_prop")添加到字段中,添加getter和setter(在camelCase中)并将@JsonProperty添加到那些(随机猜测),但没有任何改变.

问:我如何描述MyType类,以便AWS Lambda将其从snake_case正确反序列化为camelCase?

小智 5

请参阅http://docs.aws.amazon.com/lambda/latest/dg/java-programming-model-req-resp.html中的注释.

注意

您不应该依赖序列化框架的任何其他功能,例如注释.如果需要自定义序列化行为,可以使用原始字节流来使用自己的序列化.

因此,您需要从输入流序列化对象以使用注释.

http://docs.aws.amazon.com/lambda/latest/dg/java-handler-io-type-stream.html

package example;

import java.io.InputStream;
import java.io.OutputStream;
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
import com.amazonaws.services.lambda.runtime.Context; 

public class Hello implements RequestStreamHandler {
    public static void handler(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
        // TODO Serialize Object from inputStream
    }
}
Run Code Online (Sandbox Code Playgroud)