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

@JsonProperty in @JsonCreator is conflicting with @JsonProperty on mix-ins using views set on the field rather than the getter #1135

Open
NWilson opened this issue Feb 19, 2016 · 0 comments

Comments

@NWilson
Copy link

NWilson commented Feb 19, 2016

This is similar to a previous issue (#541), but I think is a bit different because the previous issue didn't use mix-ins, which might the cause of the trouble I'm getting.

public class TestData {
  public interface View {}

  public interface MixIn {
    @JsonProperty("decoratedProp")
    Long getProp();
  }

  // does not work on the field:
  // @JsonView(View.class)
  private final Long prop;

  // does work on the getter:
  @JsonView(View.class)
  public Long getProp() { return prop; }

  @JsonCreator
  public TestData(@JsonProperty("prop") Long prop) {
    this.prop = prop;
  }
}

I serialise in using an object mapper without the MixIn, using the JSON: {"prop":123}.

I serialise out using an object mapper where the MixIn has been added, using the TestData.View view. I expect to get the JSON {"decoratedProp":123}, but instead I get {"prop":123}, plus the following exception in my logs:

T+546256 [http-nio-8443-exec-6] WARN o.s.h.c.j.MappingJackson2HttpMessageConverter - Failed to evaluate serialization for type [class c.r.s.a.a.d.TestData]: java.lang.IllegalStateException: Conflicting/ambiguous property name definitions (implicit name 'prop'): found multiple explicit names: [prop, decoratedProp], but also implicit accessor: [field c.r.s.a.a.d.TestData#prop][visible=true,ignore=false,explicitName=false]

Note that the problem goes away if I switch to setting the @JsonView() annotation on the getter method, rather than the field. Also, the problem goes away if I remove the @JsonProperty() from the constructor and instead create the objects directly and then serialise them out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant