入れ子になったJSONを入力として取得するラムダ関数を実行しようとしています。私はPOJOクラスとそれらをマップしようとしています。しかし、入れ子になったJSONの値はnullを返しています。 ここで問題のサンプルを挙げました。AWSのPOJOにネストされたJSON Lambdaがnullを返す
Input:
{
"firstName": "Raj",
"lastName": "Guru",
"parameters" : {
"Address ": "Testaddress",
"POBOX" : "123"
}
}
OutPut:
Uploading function code to lambda...
Upload success. Function ARN: arn:aws:lambda:eu-central-1:938487755516:function:lambda
Invoking function...
==================== FUNCTION OUTPUT ====================
{"greetings":"Hello `Raj,` null.null"}
package com.amazonaws.lambda.demo;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
public class HelloPojo implements RequestHandler<RequestClass, ResponseClass> {
public ResponseClass handleRequest(RequestClass request, Context context){
String greetingString = String.format("Hello %s, %s.", request.getFirstName(), request.getparameters().getAddress());
greetingString+= request.getparameters().getAddress();
return new ResponseClass(greetingString);
}
---------------------------------------------------------------------------------------------------------------
package com.amazonaws.lambda.demo;
public class parameters {
private String Address;
private String POBOX;
public String getAddress() {
return Address;
}
public void setAddress(String Address) {
this.Address = Address;
}
public String getPOBOX() {
return POBOX;
}
public void setPOBOX(String POBOX) {
this.POBOX = POBOX;
}
public parameters(String Address,String POBOX) {
this.Address = Address;
this.POBOX = POBOX;
}
public parameters() {
}
@Override
public String toString(){
return getPOBOX()+getAddress();
}
}
// RequestClass:
package com.amazonaws.lambda.demo;
import com.fasterxml.jackson.annotation.JsonProperty;
public class RequestClass {
private parameters parameters = new parameters();
@JsonProperty("parameters")
public parameters getparameters() {
return parameters;
}
public void setparameters(parameters paramters) {
this.parameters = paramters;
}
package com.amazonaws.lambda.demo;
public class ResponseClass {
String greetings;
public String getGreetings() {
return greetings;
}
public void setGreetings(String greetings) {
this.greetings = greetings;
}
public ResponseClass(String greetings) {
this.greetings = greetings;
}
public ResponseClass() {
}
}
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public RequestClass(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public RequestClass() {
}
@Override
public String toString(){
StringBuilder sb = new StringBuilder();
sb.append("firstName=" + getFirstName() + "\n");
sb.append("lastName=" + getLastName() + "\n");
sb.append("parameters =" + getparameters() + "\n");
return sb.toString();
}
}