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

@JsonIgnoreProperties does not stack #1037

Open
markwoon opened this issue Dec 4, 2015 · 4 comments
Open

@JsonIgnoreProperties does not stack #1037

markwoon opened this issue Dec 4, 2015 · 4 comments
Labels
3.x Issues to be only tackled for Jackson 3.x, not 2.x

Comments

@markwoon
Copy link
Contributor

markwoon commented Dec 4, 2015

I'd like to be able to aggregate @JsonIgnoreProperties, but it looks like it's only accepting the "top" one.

Here's a test case:

  @JsonIgnoreProperties(value = { "generated" }, allowGetters = true)
  static class BaseBean {
    public String getGenerated() {
      return "http://bar.com";
    }
  }

  @JsonIgnoreProperties(value = { "computed" }, allowGetters = true)
  static class ReadOnlyBean extends BaseBean {
    public int getComputed() {
      return 32;
    }
  }

  @Test
  public void testReadOnlyProp() throws Exception {

    ObjectMapper m = new ObjectMapper();
    String json = m.writeValueAsString(new ReadOnlyBean());
    assertTrue(json.contains("generated"));
    assertTrue(json.contains("computed"));
    ReadOnlyBean bean = m.readValue(json, ReadOnlyBean.class);
    assertNotNull(bean);
  }

When the @JsonIgnoreProperties is on a mixin, the mixin's annotation trumps all.

Would it be possible to aggregate all the @JsonIgnoreProperties?

@markwoon markwoon changed the title @JsonIgnoreProperties does not stack @JsonIgnoreProperties does not stack Dec 4, 2015
@cowtowncoder
Copy link
Member

Correct, this is the current behavior, with the exception that if Class has annotation as well as property with value of that type, then both sets are combined (union is used).

This is not an optimal behavior, but it is driven by the way all annotations are handled, with respect to inheritance: since annotation handler (which also weaves in mix-ins) has no knowledge of semantics of particular annotations (nor is there a way to actually instantiate Annotation types even if it did), there is simply no way to merge annotations from super-types.

This is not to say this could never be done, but it would require significant improvements to annotation handling. I have actually thought about this, and one particular example was indeed @JsonIgnoreProperties.

So I will keep this issue open and I hope we can figure out the way to get this done in future; along with a marker that indicates alternative of full override (current behavior) as well.

Thank you for suggesting this.

@huehnerlady
Copy link

Hi, is there any update on this? Or can I vote on this change?

@cowtowncoder cowtowncoder added the 3.x Issues to be only tackled for Jackson 3.x, not 2.x label Jan 11, 2018
@cowtowncoder
Copy link
Member

@huehnerlady No -- there is no invisible magical update that just happened to be done without updating issue. We don't do that.

As to voting: if github has a mechanism feel free to. The problem here unfortunately that of implementation: to make this happen, the whole annotation processing system would need to be rewritten as per earlier comment. I hope this can be done for 3.0, but it will be ways off.

@huehnerlady
Copy link

huehnerlady commented Jan 22, 2018

@cowtowncoder thank you for your quick answer, I will keep watching this issue then and hopefully this will be done in 3.0 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Issues to be only tackled for Jackson 3.x, not 2.x
Projects
None yet
Development

No branches or pull requests

3 participants