Type conversions

There are built in type conversions for the following types:

  • int, long, boolean, Integer, Long, Boolean
  • BigDecimal, UUID, LocalDate, LocalTime, LocalDateTime

In the following example there is a type conversion for startDate and active.

@Get("/:id/:name")
HelloDto hello(int id, String name, LocalDate startDate, Boolean active) {
  ...
}
The generated code includes the type conversion with toLocalDate() and toBoolean().
ApiBuilder.get("/hello/:id/:name", ctx -> {
  ctx.status(200);
  int id = asInt(ctx.pathParam("id"));
  String name = ctx.pathParam("name");
  LocalDate startDate = toLocalDate(ctx.queryParam("startDate"));
  Boolean active = toBoolean(ctx.queryParam("active"));
  ctx.json(controller.hello(id, name, startDate, active));
});

InvalidPathArgumentException

If a parameter fails type conversion then InvalidPathArgumentException is thrown. This exception is typically mapped to a 404 response in the exception handler.

Note that path conversions imply the value can NOT be null. All other parameter types are considered optional/nullable.