-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Create extension point for ArgumentConverter #853
Comments
Please take a look at I'm not sure it makes sense to register However, I think registering additional implicit argument converters makes sense. Can you please provide an API proposal before jumping into the actual coding? |
Thanks for the hint, that worked fine. I was so stuck in the extension model thinking that I applied the custom annotation to the method, not the argument. But my point still stands, then: I have to apply that annotation to every single parameter that wants to use that converter.
Unless I'm missing something that would only be the case if the
Sure but I'm going to focus on my initial idea (extension point for arbitrary converters) as opposed to your suggestion to look into additional implicit argument converters. I think the former can be a superset of the latter. First of all, as soon as converters can be registered in several places, the question of priority and collisions arises. In the end this can be designed any way you want but I think the following order makes sense:
As a consequence the API for converters would be twofold
In both cases I would consider adding the Regarding the implementation, it looks like |
A great addition would be to support the registration of implicit (a.k.a default) converters project wide (similar to extensions) to cut down on test boilerplate. Some examples of common beneficial customizations include Jackson |
Tentatively slated for 5.6 M2 solely for the purpose of team discussion |
Team decision: Waiting for additional interest from the community. |
This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. Thank you for your contribution. |
This issue has been automatically closed due to inactivity. If you have a good use case for this feature, please feel free to reopen the issue. |
I'm also interested in a solution to register certain
It would be great if repetitive argument converters could be used implicitly without polluting the code with annotations. |
As it stands argument converters need to be applied (with
@ConvertWith
) either to a custom annotation (at least it looks like that; couldn't make it work) or to the argument. When the former is not an option (for example because you can't make it work 😉), the latter quickly becomes repetitive.An extension point that allows registering argument converters as the class and method level (much like parameter resolvers) would remedy this problem.
Beyond ease of use, this extension point would also enable creating more wholesome extensions which, applied to a test class, can register parameter resolvers, argument converters, post instance extensions, and more all in one annotation. It would also make it possible to do something like
@ConvertByCalling("fromString")
(either on class, method, or parameter), which would try to call a static methodfromString(String)
on the target type.If you think this is a valuable feature, I'd like to take a shot at implementing it.
The text was updated successfully, but these errors were encountered: