T
- Type to map.public static interface Route.Mapper<T>
Router#map(Mapper)
.
{
// we got bar.. not foo
get("/foo", () -> "foo")
.map(value -> "bar");
// we got foo.. not bar
get("/bar", () -> "bar")
.map(value -> "foo");
}
If you want to apply a single map to several routes:
{
with(() -> {
get("/foo", () -> "foo");
get("/bar", () -> "bar");
}).map(v -> "foo or bar");
}
You can apply a Route.Mapper
to specific return type:
{
with(() -> {
get("/str", () -> "str");
get("/int", () -> 1);
}).map(String v -> "{" + v + "}");
}
A call to /str
produces {str}
, while /int
just
1
.
NOTE: You can apply the map operator to routes that produces an output.
For example, the map operator will be silently ignored here:
{
get("/", (req, rsp) -> {
rsp.send(...);
}).map(v -> ..);
}
Modifier and Type | Method and Description |
---|---|
static Route.Mapper<Object> |
chain(Route.Mapper it,
Route.Mapper next)
Produces a new mapper by combining the two mapper into one.
|
static <T> Route.Mapper<T> |
create(String name,
org.jooby.funzy.Throwing.Function<T,Object> fn)
Creates a new named mapper (just syntax suggar for creating a new mapper).
|
Object |
map(T value)
Map the type to something else.
|
default String |
name() |
@Nonnull static Route.Mapper<Object> chain(Route.Mapper it, Route.Mapper next)
it
- The first mapper to apply.next
- The second mapper to apply.@Nonnull static <T> Route.Mapper<T> create(String name, org.jooby.funzy.Throwing.Function<T,Object> fn)
T
- Value type.name
- Mapper's name.fn
- Map function.Copyright © 2019. All rights reserved.