-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Simplify registration of Jackson mixin types #30152
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
Conversation
Hi, thanks for your contribution!
When adding a private void addJsonMixinBeans(ListableBeanFactory beanFactory) {
String[] names = beanFactory.getBeanNamesForAnnotation(JsonMixin.class);
for (String name: names) {
Class<?> type = beanFactory.getType(name);
addJsonMixinBean(type);
}
} then Spring will not try to instantiate the bean. You're only interested in the type of the bean, anyway. This way abstract beans and interfaces work. But I'm not sure if that solution isn't too hacky. @wilkinsona what do you think? If you want to play around with it, the changes are on this branch.
That's the same as with |
Thank you very much for your guidance @mhalbritter . Adding |
I don't think |
Thank you so much for your reply @wilkinsona, very good suggestion. I will adjust the way to find |
Hi, I updated the PR and it is ready to be reviewed again. |
This is looking really good now, @terminux. Thank you. The only thing I'm not completely sure about is the need for |
We discussed this today on our team call and we'd like to proceed but without the |
Thanks very much for the contribution, @terminux. |
Hi, this PR basically solves #25920, but there are still some issues to consider:
Boot finds classes annotated with
@JsonMixin
Mix-in classes are mostly abstract classes or interfaces.
I refer to the implementation of
JsonComponentModule
and use theListableBeanFactory#getBeansWithAnnotation
method to find the mix-in class, but the@Component
annotation does not apply to an abstract class or interface unless it contains a method annotated with@Lookup
.If the user customizes the
MappingJackson2HttpMessageConverter
,@JsonMixin
may not work, for example:Closes gh-25920