Open
Description
Given the discussions on #3496 (and corresponding PR #3494) as well as the new @BindParam
I think the reflective bean converter needs some cleanup and possibly should be available as public API.
Some issues:
- It is bizarre how it does not implement
BeanConverter
which makes looking for it tricky. - Strangely it gets created on every request as a fallback. Maybe escape analysis is working and it is fine performance wise but it makes me wonder if it is threadsafe when I see that.
- Ideally it uses MethodHandles instead of the older reflection API.
The last point is important in a modular world. There are two choices in allow reflective access if your application is modular. You either
open
everything up (as in putopen
module declaration or package)- or you pass a
MethodHandles.Lookup
to the library (jooby) doing the reflection.
Thus we should allow one want to do something like (the following may not be correct but roughly):
Jooby app = ...;
var lookup = MethodHandles.lookup(); // the consumer of jooby calls this
app.converter(new ReflectiveBeanConverter(lookup)); // or however we replace the default one.
On a separate note Handlebars.java should do something similar for version 5. In fact you could do
var lookup = MethodHandles.lookup(); // the consumer of jooby calls this
app.registerLookup(lookup); // register lookup to be used by jooby modules.
// jooby handlebars module then does
var lookup app.getLookup();
Handlebars handlebars = new Handlebars(lookup); // or whatever is analogous
I can try to take a stab at a PR if you like. A bonus to using MethodHandles is that they are supposedly can be faster than regular reflection.