Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tpsb opened this issue Mar 29, 2019 · 1 comment
Open
Labels

Comments

@tpsb
Copy link

tpsb commented Mar 29, 2019

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.

@cowtowncoder
Copy link
Member

Hmmh. Good question.

I think the behavior is simply side-effect of implementation: @JsonAnyGetter properties are processed with no regard to views. In fact they are handled outside scope of logical properties and can also produce duplicates.

But I think that your suggestion of View applying to the whole set makes sense, and that this is basically a missing feature.

I don't know if I will have time to implement it any time soon, but it does make sense to me.

@cowtowncoder cowtowncoder changed the title JsonAnyGetter does not respect view settings if there is an active view set @JsonAnyGetter does not respect view settings if there is an active view set Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants