Skip to content

mvc: Add BindParam annotation for custom parsing/mapping #3472

@jknack

Description

@jknack

In addition to exising *Param annotation, Jooby will support a new annotation BindParam that allow you to convert current HTTP context to a desire type.

Case 1: instance method on controller:

@GET("/new-bind")
public Response doSomething(@BindParam MyBean q) {
   return ...;
}

MyBean bind(Context ctx) {
   // build MyBean from ctx as you want
}

Case 2: static method on Mapping class

@GET("/new-bind")
public Response doSomething(@BindParam(MyConverter.class) MyBean q) {
   return ...;
}
class MyConverter {
   public static MyBean convert(Context ctx) {
    // build MyBean from ctx as you want
   }
}

In both cases mapping is function must take io.jooby.Context as argument and returns the required type. Function/method name is optional.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions