Skip to content

@ResultType: new annotation for source code generator #3447

Description

@jknack

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() {}
   }
 }
  • Write a code generator:
 @ResultType(types = MySpecialType.class, handler = "customMapping")
 class MySpecialTypeGenerator {

      public static Route.Handler customMapping(Route.Handler handler) {
          return myHandler.then(handler);
      }
  }
  • Let jooby annotation processor to know about your handler by setting the jooby.handler annotation processor option:

    jooby.handler=mypackage.MySpecialTypeGenerator

  • Generates:

     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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions