0 votes
1 view
in AWS by (18.2k points)

I'm calling an aws lambda with a json body. So the fields of the json are with a different name from the ones in the POJO. So what I did is to add @JsonProperty on the fields to tell jackson what are the names in json. But for some reason, it seems that it doesn't recognize them and all the fields are null. If I pass a json with the same field names as the POJO it's working. Here's my class: 

public class Event implements Identifiable {



    private String distinctId;



    private Integer userId;


    @JsonDeserialize(using = LocalDateTimeDeserializer.class)

    @JsonSerialize(using = LocalDateTimeSerializer.class)

    private LocalDateTime eventDateTime;


    //Here are the getters and setters


If I pass 

{"distinct_id":"123", "user_id":123, "dt":"2017-01-04T08:45:04+00:00"} 

all the fields are null and with distinctId, userId, eventDateTime it's serializing ok with the exception that it also doesn't recognize my custom serializers/deserializers but this actually is the same problem.

1 Answer

0 votes
by (42.4k points)

To get input and output streams to work with, you need to implement RequestStreamHandler.

import com.amazonaws.services.lambda.runtime.RequestStreamHandler


public class ChartHandler implements RequestStreamHandler {

    private ObjectMapper objectMapper = new ObjectMapper();



    public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {

        DeserializationClass deserializedInput = objectMapper.readValue(inputStream, DeserializationClass.class)

        objectMapper.writeValue(outputStream, deserializedInput); //write to the outputStream what you want to return




If you have the input and output streams, you can use any framework or format to parse it.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 29 in Java by Suresh (3.4k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !