Skip to content

Nulls.AS_EMPTY returns null in java.lang.Object #3489

Open
@aivinog1

Description

@aivinog1

Describe the bug
When I'm using JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY, Nulls.AS_EMPTY) for nullable value with type java.lang.Object in a Map, I still getting the null in the deserialized object. I think that problem is that com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer.Vanilla doesn't override com.fasterxml.jackson.databind.JsonDeserializer#getEmptyValue(com.fasterxml.jackson.databind.DeserializationContext). I think that the deserializer for object should return empty object in the getEmptyValue method.

Version information
2.13.2.2

To Reproduce
If you have a way to reproduce this with:

  1. Create a JSON, like this:
{
  "a": {
    "first": "second",
    "third": null
  }
}
  1. Create this class to deserialize with:
import java.util.Map;

public class Scratch {
    private Map<String, Object> a;

    public Map<String, Object> getA() {
        return a;
    }

    public void setA(Map<String, Object> a) {
        this.a = a;
    }
}
  1. Create the ObjectMapper and override nullable behavior:
        final ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configOverride(Map.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY, Nulls.AS_EMPTY));
  1. Deserialize this JSON:
        String json = "...";
        final Scratch scratch = objectMapper.readValue(json, Scratch.class);
  1. Verify that in the a object we got a null in the third key:
        final Object third = scratch.getA().get("third");
        assert third != null; // fails

Expected behavior
I'm expecting that the empty value of the java.lang.Object is a new Object instance.

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