Skip to content

@JsonValue not considered when evaluating inclusion #2909

@chrylis

Description

@chrylis

I have an object (a links holder) that is essentially a container around a java.util.Map. The map is annotated with @JsonValue, and this behaves as expected (the map is dumped as a JSON object inline).

However, I only want this included when the map is non-empty, so I annotated the getLinks() method with @JsonInclude(NON_EMPTY). However, it appears that the inclusion filter is applied before the value substitution, so it is always included even as {}.

I'm using Jackson 2.11.2 (managed via Spring Boot).

@Data
class Wrapper {
  @JsonValue
  Map<String, String> values;
}

@Data
class TopLevel {
  @JsonInclude(NON_EMPTY)
  Wrapper nested;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions