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

Should ignore org.hibernate.bytecode.internal.javassist.FieldHandled.getFieldHandler() #72

Closed
candrews opened this issue Jun 30, 2015 · 6 comments
Milestone

Comments

@candrews
Copy link

When using bytecode enhancement, Hibernate classes get a new field, "fieldHandler" from the org.hibernate.bytecode.internal.javassist.FieldHandled interface. You can see how to set up bytecode enhancement and see what the generated code looks like at http://vladmihalcea.com/2014/09/08/hibernate-bytecode-enhancement/

This field should not be serialized/deserialized by Jackson.

Here's the module I've made to workaround this:

private static class FiledHandledModule extends SimpleModule {
    private abstract class FieldHandledMixIn implements FieldHandled {

        @Override
        @JsonIgnore
        public abstract void setFieldHandler(FieldHandler handler);

        @Override
        @JsonIgnore
        public abstract  FieldHandler getFieldHandler();

    }

    @Override
    public void setupModule(SetupContext context) {
        super.setupModule(context);
        context.setMixInAnnotations(FieldHandled.class, FieldHandledMixIn.class);
    }

}
@cowtowncoder
Copy link
Member

Thank you for reporting this.

From the article, it sounds like version 4.2.8 of Hibernate and above may be affected.
Do you think it'd be easy to come with a unit test that shows the problem?

I'll have to think about the best way to approach this: mix-in is one possibility, but perhaps "ignore type" could also work, to drop the property with FieldHandler value.

@candrews
Copy link
Author

Based on git history, https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/bytecode/internal/javassist/FieldHandled.java has existed since Hibernate 4.0 and continues to exist in Hibernate 5. So I think it's safe to ignore its fields for all Hibernate 4 and 5 versions.

@cowtowncoder
Copy link
Member

Ok makes sense; thank you for verifying.

@cowtowncoder
Copy link
Member

This would be easyish to implement if [https://github.com/FasterXML/jackson-databind/issues/861] was implemented. Until then, should be relatively easy to implement by making HibernateAnnotationIntrospector override AnnotationIntrospector.isIgnorableType().

In fact, the bigger piece that is needed is really the unit test to verify the fix.
I would be happy to merge a PR for this! :)

@cowtowncoder cowtowncoder added this to the 2.7.0-rc3 milestone Dec 27, 2015
@cowtowncoder
Copy link
Member

Ok. I added possible fix for annotation introspectors, but unfortunately I have no way to test whether that actually works. If fix does not work a unit test would be welcome, and issue may be reopened.

@cowtowncoder
Copy link
Member

Oy vey. As per #86, this type is now removed from Hibernate 5.1.
But sounds like it is still needed for 5.0. Also not certain if replacement functionality would be needed.

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