FasterXML / FasterXML/jackson-databind

Is there a way to skip null values for properties handled by @JsonAnySetter?

Open
#6,170 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
3.7k
Forks
1.5k
Avg merge
3d 5h
Merged PRs (30d)
30

Description

### Discussed in https://github.com/FasterXML/jackson-databind/discussions/6169

Originally posted by **margarita-sk** August 20, 2026
When configuring JsonMapper with null handling:

```
.changeDefaultNullHandling(v -> v.withValueNulls(Nulls.SKIP))
.changeDefaultNullHandling(v -> v.withContentNulls(Nulls.SKIP))
```
the configuration appears to have no effect on properties handled by @JsonAnySetter.

### Reproduction
```
class Jackson3Test {

@Test
void testSkipNullValuesInJsonAnySetter() {
JsonMapper jsonMapper = JsonMapper.builder()
.changeDefaultNullHandling(v -> v.withValueNulls(Nulls.SKIP))
.changeDefaultNullHandling(v -> v.withContentNulls(Nulls.SKIP))
.build();

String json = """
{
"non_null_property": "test",
"null_property": null
}
""";
TestPojo input = jsonMapper.readValue(json, TestPojo.class);

Assertions.assertEquals(1, input.getDynamicProperties()
.size()); // is failed, but expected to pass because of the default null handling configuration
}

static class TestPojo {

private final Map dynamicProperties = new HashMap<>();

@JsonAnySetter
public void setDynamicProperties(String key, JsonNode value) {
this.dynamicProperties.put(key, value);
}

public Map getDynamicProperties() {
return this.dynamicProperties;
}

}

}
```

### Actual behavior
The @JsonAnySetter method is invoked for both properties, including the property whose value is null.

### Expected behavior
With the mapper configured with:
```
.changeDefaultNullHandling(v -> v.withValueNulls(Nulls.SKIP))
.changeDefaultNullHandling(v -> v.withContentNulls(Nulls.SKIP))
```
I would expect the null_property value to be skipped and the @JsonAnySetter method not to be invoked for it.

### Question
Is the current behavior intentional for @JsonAnySetter?
If this is intentional, is there currently a recommended way to configure @JsonAnySetter to skip null values?
If it is not intentional, is support for applying Nulls.SKIP to @JsonAnySetter planned for Jackson 3?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the JsonMapper reproduction from the issue and trace how @JsonAnySetter receives properties during deserialization. Add a regression test covering the configured Nulls.SKIP behavior, with the null_property entry not invoking the setter while non_null_property remains handled.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.