Skip to content
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

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

Open
jknack opened this issue Sep 29, 2024 · 0 comments
Labels

Comments

@jknack
Copy link
Member

jknack commented Sep 29, 2024

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 jknack added the feature label Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant