`@JsonValue` ignores name filters on the enclosing property

Open
#6,418 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
backend

Research direction

Start with the bean serializer’s lookup of name filters for properties serialized through @JsonValue, then trace how contextual properties expose their member; the report identifies the change from #6076 and says #3647 covers filters on the accessor. Reproduce with the supplied Holder example and verify that ignore, include, and plain each serialize only keep. PR #6414 proposes a fix, so check its status before starting.

Written by the indexing model from the issue text.

Description

I used DeepSeek to translate this report into English.

Search before asking
  • I searched in the issues and found nothing similar.
Describe the bug

Jackson Databind 3.3.0 ignores @JsonIgnoreProperties and @JsonIncludeProperties on an enclosing property when the property value is serialized through @JsonValue. The example below writes drop under both ignore and include. The directly serialized plain property still filters it out.

Version Information

Reproduced with 3.3.0 on JDK 17. The same example works in 3.2.4 and at 3ad2bb7e, and first fails at 6a17bd06 (#6076).

Reproduction
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonIncludeProperties;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonValue;
import tools.jackson.databind.json.JsonMapper;

class Repro {
    @JsonPropertyOrder({"keep", "drop"})
    record Payload(int keep, int drop) {}

    static class Wrapper {
        @JsonValue
        public Object value() {
            return new Payload(1, 2);
        }
    }

    @JsonPropertyOrder({"ignore", "include", "plain"})
    static class Holder {
        @JsonIgnoreProperties("drop")
        public Wrapper ignore = new Wrapper();

        @JsonIncludeProperties("keep")
        public Wrapper include = new Wrapper();

        @JsonIgnoreProperties("drop")
        public Payload plain = new Payload(1, 2);
    }

    public static void main(String[] args) {
        System.out.println(JsonMapper.builder().build().writeValueAsString(new Holder()));
    }
}

Actual output on 3.3.0

{"ignore":{"keep":1,"drop":2},"include":{"keep":1,"drop":2},"plain":{"keep":1}}
Expected behavior

All three properties should contain only keep.

{"ignore":{"keep":1},"include":{"keep":1},"plain":{"keep":1}}
Additional context

After #6076, getMember() on the contextual property returns the @JsonValue accessor. The bean serializer looks up name filters on that member and misses the annotations on the enclosing property. #3647 covered filters declared on the accessor itself.

PR #6414 proposes a fix for Bean and Map values.

Dominant language
Java
Stars
3.8k
Forks
1.6k
Avg merge
1d 18h
Merged PRs (30d)
59

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from FasterXML/jackson-databind

All issues in FasterXML/jackson-databind

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.