Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda RequestHandler does not return nulls in response #281

Closed
SamStephens opened this issue Nov 26, 2021 · 1 comment
Closed

Lambda RequestHandler does not return nulls in response #281

SamStephens opened this issue Nov 26, 2021 · 1 comment

Comments

@SamStephens
Copy link

SamStephens commented Nov 26, 2021

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.

@msailes
Copy link
Collaborator

msailes commented Jan 5, 2022

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

@msailes msailes closed this as completed Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants