jooby icon indicating copy to clipboard operation
jooby copied to clipboard

jooby-apt: add a new bean factory processor (as replacement/alternative of ReflectiveBeanConverter)

Open jknack opened this issue 1 year ago • 0 comments

interface BeanFactory {
   <T> create(Context ctx, Class<T> type);
}

With:

{
   install(new ModelBeanFactory());

   get("/bean", ctx -> {
        var person = ctx.query(Person.class);
   });
}

Or:

class Controller {
   @GET
    public Person bean(@QueryParam Person person) {
    }
}

The [Model]BeanFactory will be generated by jooby-apt and will looks like:

class ModelBeanFactory implements BeanFactory {

   <T> create(Context ctx, Class<T> type) {
       if (type == Person.class) {
            return createPerson(ctx);
       }
      throw new Unsupported();
   }

   Person createPerson(Context ctx) {
      var value = new Person();
      value.setName(ctx.lookup("name").value());
      return value;
   }
}

TBD: How the processor find these beans? Should we introduce a new annotation? package/class name matches?

NOTE 1: I would like to introduce it for 3.x. On 4.x remove the reflective bean converter.

NOTE: This is the last step on removing reflection from jooby (core).

jknack avatar Sep 29 '24 15:09 jknack