jooby-project / jooby

The modular web framework for Java and Kotlin
https://jooby.io
Apache License 2.0
1.7k stars 199 forks source link

@ResultType: new annotation for source code generator #3447

Closed jknack closed 3 months ago

jknack commented 3 months ago

Hints source code generator (jooby annotation processor) to map/adapt a specific return type to use a custom handler. This annotation if only for source code generator process so only applies for MVC routes. Example:

   class MyController {
     @GET("/")
     public MySpecialType hello() {}
   }
 }
 @ResultType(types = MySpecialType.class, handler = "customMapping")
 class MySpecialTypeGenerator {

      public static Route.Handler customMapping(Route.Handler handler) {
          return myHandler.then(handler);
      }
  }
     app.get("/", customMapping(this::hello));

This new annotation replaces the existing ResultHandler supports which works at runtime, while this one works at compile time.

see #3422