13.1.5 Retaining Parameter Names

By default with Java, the parameter name data for method parameters is not retained at compile time. This can be a problem for Micronaut if you do not define parameter names explicitly and depend on an external JAR that is already compiled.

Consider this interface:

Client Interface

  1. interface HelloOperations {
  2. @Get("/hello/{name}")
  3. String hello(String name);
  4. }

At compile time the parameter name name is lost and becomes simply arg0 when compiled against or read via reflection later. To avoid this problem you have two options. You can either declare the parameter name explicitly:

Client Interface

  1. interface HelloOperations {
  2. @Get("/hello/{name}")
  3. String hello(@QueryValue("name") String name);
  4. }

Or alternatively it is recommended that you compile all byte code with -parameters flag to javac. See Obtaining Names of Method Parameters. For example in build.gradle:

build.gradle

  1. compileJava.options.compilerArgs += '-parameters'