How to bind parameters in Micronaut controller in Kotlin?

1k Views Asked by At

See code in gist: https://gist.github.com/C06A/e80b783a1d34cc9d80e339da0d7b5b53

This is a small sample project I try to make with Micronaut in Kotlin.

Unfortunately the only parameters binding I was able to do as in the code. They require the pattern in the template and typed as String. However I would like to be able to do something like in comments. So there won't be a pattern in the template and types as Number and List (or Array would work as well).

Is it possible to do that and why it doesn't work for me?

2

There are 2 best solutions below

6
James Kleeh On

The first argument you can just simply type as a Number. The second argument however you would have to pull in as a String because its not possible for Micronaut to know how the part of the URI should be converted to a list.

/repeat/5/1,2,3,4 ? /repeat/6/1|2|3 ? /repeat/7/[1,2,3]

5
C.A.B. On

I found somewhere that the pattern "/{+stack}" would match the string including slashes. This is not what I am looking for, but helpful in the mean time. This also doesn't allow to make this parameter optional. Oh well! :-(