Skip to content

Lambda RequestHandler does not return nulls in response #281

Closed

Description

@SamStephens

I have a Java Lambda that I wish to sometimes populate a key with a string value, and sometimes set it to null, to indicate that the key is not meaningful in this case.

However if I set a key to have the value null, that key is not included in the output. Repro code:

public class App implements RequestHandler<Map<String, Object>, Map<String, Object>> {
    @Override
    public Map<String, Object> handleRequest(Map<String, Object> input, Context context) {
        HashMap<String, Object> output = new HashMap<>();
        output.put("nonNulllKey", "nonNull");
        output.put("nullKey", null);
        return output;
    }
}

If you create a Lambda with this code, the result will include nonNulllKey, but not nullKey.

I've checked this is not a Lambda limitation by returning a None value in Python and confirming I can see the key with the null value in the response.

Activity

  1. msailes commented on Jan 5, 2022

    @msailes
    Contributor

    Hi @SamStephens,

    The Java serialisation code and configuration can be found here JacksonFactory.java. It is configured to ignore nulls.

    Changing this behaviour would likely effect another user.

    With the next major version of the events library customers will have the ability to bring their own serialiser. This would give you the ability to configure the behaviour to match that of the Python runtime.

    Mark

  2. SamStephens commented on Aug 29, 2025

    @SamStephens
    Author

    @msailes sorry I didn't see this earlier. This is a nasty limitation, it prevents Java users from returning null values. I understand the fear of backwards incompatible changes, but I'd ask the in the next major version, the default configuration retains null keys, as the distinction between a missing key and a null key can be a semantically important one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions