Limit to number of arguments in a controller method in NinjaFramework?

100 Views Asked by At

I'm using NinjaFramework 6.0, tried adding a 10th @Param to my controller method and now I get "No suitable method found for with(Controller[...]Index)" error compiling the Routes.java.

My method looks like this:

public Result personIndex(
        @Param("ssn") Optional<String> ssn,             
        @Param("dodId") Optional<String> dodId,             
        @Param("firstName") Optional<String> firstName, 
        @Param("middleName") Optional<String> middleName, 
        @Param("lastName") Optional<String> lastName,
        @Param("birthday") Optional<String> birthday, 
        @Param("branch") Optional<String> branch, 
        @Param("rateRank") Optional<String> rateRank, 
        @Param("status") Optional<String> status, 
        @Param("page") Optional<Integer> page) { ... }

If I remove one of the params then everything will compile and work. Is this a hard limit? Should I encapuslate these into some sort of form / dto object?

--

This appears to be a problem when using this type of Route configuration:

router.GET().route("/persons").with(PersonController::personIndex);

If I switch to the 'old' way it works fine:

router.GET().route("/persons").with(PersonController.class, "personIndex");

1

There are 1 best solutions below

0
FrEaKmAn On

While browsing Ninja docs (http://www.ninjaframework.org/documentation/basic_concepts/routing.html), I noticed the following text

The class ninja.ControllerMethods defines the various interfaces that are acceptable method signatures for Java 8 lambda expressions. A controller method returns a ninja.Result and has anywhere from 0 to 12 arguments. If you need more than 12 arguments, you can fallback to Ninja’s legacy routing strategy of Class + “method”.

Not sure if something changed from 6.0 version, but 10 params should work.