Binding Bindable values to POJO

    Binding Bindable values to POJO

    1. @Controller("/api")
    2. class MovieTicketController {
    3. // You can also omit query parameters like:
    4. // @Get("/movie/ticket/{movieId}
    5. @Get("/movie/ticket/{movieId}{?minPrice,maxPrice}")
    6. HttpStatus list(@Valid @RequestBean MovieTicketBean bean) {
    7. return HttpStatus.OK
    8. }
    9. }

    Bean definition

    1. @Introspected
    2. public class MovieTicketBean {
    3. private HttpRequest<?> httpRequest;
    4. @PathVariable
    5. private String movieId;
    6. @Nullable
    7. @PositiveOrZero
    8. private Double minPrice;
    9. @Nullable
    10. @QueryValue
    11. @PositiveOrZero
    12. private Double maxPrice;
    13. public MovieTicketBean(HttpRequest<?> httpRequest, String movieId, Double minPrice, Double maxPrice) {
    14. this.httpRequest = httpRequest;
    15. this.movieId = movieId;
    16. this.minPrice = minPrice;
    17. this.maxPrice = maxPrice;
    18. }
    19. public HttpRequest<?> getHttpRequest() {
    20. return httpRequest;
    21. }
    22. return movieId;
    23. }
    24. @Nullable
    25. public Double getMaxPrice() {
    26. return maxPrice;
    27. }
    28. @Nullable
    29. public Double getMinPrice() {
    30. return minPrice;
    31. }
    32. }

    Bean definition

    1. @Introspected
    2. data class MovieTicketBean(val httpRequest: HttpRequest<Any>,
    3. @field:PathVariable val movieId: String,
    4. @field:QueryValue @field:PositiveOrZero @field:Nullable val minPrice: Double,
    5. @field:QueryValue @field:PositiveOrZero @field:Nullable val maxPrice: Double)

    Bean class has to be introspected with @Introspected. It can be one of:

    1. Mutable Bean class with setters and getters