Skip to content

Route inheritance from base controller no longer works when multiple subclasses extend it (Jooby 4.x vs 1.x) #3786

@goodcwj

Description

@goodcwj

Description

In Jooby 4.0.7, routes from a base controller are not inherited by subclasses as expected.
This behavior worked correctly in Jooby 1.x.

Example

BaseController.java

@Path("/base")
public abstract class BaseController {

  @GET
  public String base() {
    return "base";
  }

  @GET("/withPath")
  public String withPath(@QueryParam String q) {
    return "withPath";
  }

  @GET("/{id}")
  public String getOne(Context ctx) {
    return "base: " + ctx.path("id").value();
  }
}

SubClass 1

@Path("/inherited")
public class Controller1552 extends BaseController {
  @GET("/childOnly")
  public String childOnly(Context ctx) {
    return ctx.getRequestPath();
  }

  @POST("/childOnly")
  public String childOnlyPost(Context ctx) {
    return ctx.getRequestPath();
  }
}

SubClass 2

@Path("/overrideMethod")
public class OverrideMethodSubClassController extends BaseController {
  @POST("/user")
  public String newPath(Context q) {
    return "/overrideMethod/user";
  }

  @GET("/childOnly")
  public String childOnly(Context ctx) {
    return ctx.getRequestPath();
  }
}

App.java

mvc(new OverrideMethodSubClassController_());
mvc(new Controller1552_());

Actual result (Jooby 4.0.7)

POST /overrideMethod/user
GET  /overrideMethod/childOnly
GET  /inherited/childOnly
POST /inherited/childOnly
GET  /inherited
GET  /inherited/withPath
GET  /inherited/{id}

Expected:

/overrideMethod should also include inherited routes from BaseController.

Related

#1552
— similar issue, but this happens when multiple subclasses extend the same base controller.

Environment

  1. Jooby: 4.0.7
  2. JDK: 21
  3. Build: Gradle (joobyRun)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions