Skip to content

@JsonAnyGetter does not respect view settings if there is an active view set #2289

@tpsb

Description

@tpsb

For the following setup:

public interface A {}
public interface B {}

public class Phone {
  private static Map<String, String> attrs = new HashMap<>();
  static {
    attrs.put("displaySize", "5.8 in");
  }

  @JsonView(A.class)
  public String getName() {
    return "some phone";
  }

  @JsonView(B.class)
  @JsonAnyGetter
  public Map<String, String> getAttrs() {
    return attrs;
  }
}

I would expect properties contained by the map annotated with @JsonAnyGetter not to be included in the serialized form if serialization is done with an active view of A.class. The generated JSON object should contain only name property.

In version 2.9.8 it does not work this way. Properties from the @JsonAnyGetter map seem to be included unconditionally. The behavior is the same if the @JsonView annotation is removed from the method and DEFAULT_VIEW_INCLUSION is disabled.

Is it like this by design or can it be considered a bug or a missing feature 😉 ?

If it's the second case I would like to request such a fix/feature as I think covering @JsonAnyGetter by view handling would be much more intuitive.

I guess the settings should likewise be honored on deserialization (@JsonAnySetter) if it is done with an active view.

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.xIssues to be only tackled for Jackson 3.x, not 2.x

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions