You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Lambda RequestHandler does not return nulls in response #281
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.
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.
@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.
Activity
msailes commentedon 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
SamStephens commentedon Aug 29, 2025
@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.