-
Notifications
You must be signed in to change notification settings - Fork 40
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
Allow users to "annotate" classes outside of their source control #111
Comments
Wouldn’t be something like Jacksons Mixins a useful alternative to MP Config to annotate existing classes? An existing class like: public class MyPojo {
private String field;
public String getField() {
return field;
}
public void setField(String field) {
this.field = field;
}
} could then be “annotated” with a “mixin”-interface or (abstract-) class like: @Mixin(MyPojo.class)
@Name("Pojo")
@Description("A pojo is intended for...")
public interface MyPojoMixin {
@NonNull
public String getField();
@Ignore
public void setField(String field);
} This would just need one new annotation and no new config options, all existing annotations would also be useable on “mixin”-types. |
Sounds like a good idea ! However we should possibly create our own annotations as to not expose implementations on the boundary. Mixins might be something that can be shared with other MP api's ? |
As far as I know there is currently no such annotation, so a new annotation need to be created anyways. This could indeed be useful for other MP api's like MP OpenApi, for the same usecase. Is there any project for such shared "things"? |
No there is not. At least not as far as I know :) |
Added an example in https://github.com/ybroeker/smallrye-graphql/tree/feat/mixin, maybe it is interesting for you. |
I think that mixins should also consider CDI The whole annotation resolving mechanism is getting quite complex:
Spring does even more things like aliases for annotation properties, etc. As this is required by so many projects, I guess it should become a separate project, maybe even a separate MP standard, so all MP standards can be based on it. It even has the potential of becoming part of CDI some day. P.S.: A few years ago, I extracted some of these mechanisms to https://github.com/t1/stereotype-helper |
We've just talked about this issue on the working group weekly. We need feedback on the library that we may want to use: https://github.com/t1/power-annotations |
I'm thinking about another really cool use-case for mixins: say we're developing an application packed with annotations from JPA, which doesn't support mixins (yet). The application also uses a library that supports mixins but doesn't know about JPA, e.g. a future MP GraphQL. We want all JPA @MixinFor(javax.persistence.Id.class)
@org.eclipse.microprofile.graphql.Id
public class PersistenceIdMixin {} Voila! MP GraphQL would work as if all JPA This would become even more interesting, when the annotation values could be mapped, so, e.g., OpenAPI annotations could also serve as GraphQL I'm working on implementing this in Power Annotations. |
Annotation-mixins work now. Next I'll try to use it for the typesafe client... in a separate branch, as we've discussed. |
We will work on this in smallrye before we pull it up into MP GraphQL. You may want to look here. |
The use case here is for users who pull in third party binaries that they want to use as GraphQL entities, but then rename or add a description, etc.
One thought would be to use MP Config to "annotate" the third party classes without changing the code - something like:
This might take some more thought - for type name/description, it might be easy enough to use MP Config, but then users may also want to declaratively rename or ignore certain fields/getters/setters, and then things get a little more complicated.
The text was updated successfully, but these errors were encountered: