-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add ConfigurationConverter for Java Records to allow Records as complex configuration elements #165
Comments
@HannesWell Any idea if that can be supported (e.g. via reflection) while still emitting class files compatible with Java 8? Calling a constructor implicitly for type conversion has been added in eclipse-sisu/sisu.plexus#43 but that isn't sufficient for record support (as that is just supporting a single argument constructor of type String). Would you be able to come up with a PR? |
ASM has some support for records: https://asm.ow2.io/javadoc/org/objectweb/asm/RecordComponentVisitor.html. Maybe that can be used for this case or at least some inspiration taken from it. |
Thanks for the hint. We could do something like in https://stackoverflow.com/a/67126110 to find the caconical constructor and call it with the element names matched to component-names (passing null for missing ones).
Sure I can try to provide one (probably in the next days). |
The method https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Class.html#getRecordComponents() is only available in Java 16 or above so even that one probably needs to be called via reflection. |
Record classes available since Java-16 seem to be convenient to model complex configuration elements of a Maven Mojo, if that Plugin requires at least Java-16.
Therefore it would be great to add a ConfigurationConverter that supports records similar to the
ObjectWithFieldsConverter
orEnumConverter
.It might be already sufficient to have a
ObjectWithFieldsConverter
that uses 'Constructor'-injection and calls the suitable constructor.But finding the suitable constructor might be non-trivial. It probably should consider
java.lang.reflect.Parameter.getName()
(but that is not necessarily present) a reasonable strategy is needed if not all record components are specified and the record has an alternative constructor.The text was updated successfully, but these errors were encountered: