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

MixIn @JsonProperty for Object.hashCode() is ignored #1990

Closed
freddyboucher opened this issue Apr 6, 2018 · 2 comments
Closed

MixIn @JsonProperty for Object.hashCode() is ignored #1990

freddyboucher opened this issue Apr 6, 2018 · 2 comments
Milestone

Comments

@freddyboucher
Copy link

Hi,

The following code works well in 2.8.10 but not anymore with 2.8.11, neither with 2.9.x

public class MixinTest {

    @Test
    public void testMixin() throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.addMixIn( Object.class, ObjectMixIn.class );

        Assert.assertEquals( "{\"hashCode\":1864350231}", objectMapper.writeValueAsString( new Bean() ) );
    }

    public class Bean {
    }

    @JsonPropertyOrder( alphabetic = true )
    public interface ObjectMixIn {

        @Override
        @JsonProperty
        int hashCode();
    }
}

Is it expected? I didn't see anything in the release notes.
Thanks

@cowtowncoder
Copy link
Member

Ok, first things first: behavior should not have changed in 2.8 patch, and that is unfortunate.

Second: I think I know what kind of change could cause this. Mix-in handling code did allow mix-ins from java.lang.Object, with quite a bit of extra handling. When refactoring handling, as part of rewriting annotation introspection system (for unrelated thread-safety issues), it is possible this was dropped. I was speculating that the only possible reason for mix-ins in java.lang.Object would be inclusion of hashCode() for serialization... looks like I was right on that. :)

So most likely change in 2.9 changed behavior (which itself is not great), but worse, instead of change in minor version, patch was also affected. That is really unfortunate.

@cowtowncoder cowtowncoder added 2.9 and removed ACTIVE labels Apr 20, 2018
@cowtowncoder cowtowncoder added this to the 2.9.6 milestone Apr 20, 2018
@cowtowncoder cowtowncoder changed the title Regression: MixIn @JsonProperty is ignored in 2.8.11 (works well in 2.8.10) MixIn @JsonProperty for Object.hashCode() is ignored Apr 20, 2018
@cowtowncoder
Copy link
Member

Ok, yes. Rewrite of annotation collection for 2.8 did break this somewhat specialized case.
I was able to fix this for 2.9 (and going forward), but since 2.8 is closed (except for critical fixes) I won't try patching it there.

Thank you for reporting this.

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

2 participants