Except all JSR311 related annotations ( Include extend by Zero such as @BodyParam, @StreamParam etc ), zero also support some default typed parameters, these kind of parameters do not require any annotations in your code, but with Java Type instead directly. Zero will scan the method and pick up the parameters by type instead of annotation. All support types are as following:
-
io.vertx.core.Vertx
-
io.vertx.core.buffer.Buffer
-
io.vertx.core.eventbus.EventBus
-
io.vertx.core.http.HttpServerRequest
-
io.vertx.core.http.HttpServerResponse
-
io.vertx.core.json.JsonArray
-
io.vertx.core.json.JsonObject
-
io.vertx.ext.auth.User
-
io.vertx.ext.web.FileUpload
-
io.vertx.ext.web.RoutingContext
-
io.vertx.ext.web.Session
All above list types are default supported by zero.
Demo projects:
- Standalone - 6083:
up-rhea
package up.god.micro.params;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.up.annotations.EndPoint;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@EndPoint
@Path("/api")
public class TypedExecutor {
@POST
@Path("param/typed/json")
public JsonObject sendJson(
final JsonObject json) {
System.out.println(json);
return json;
}
@POST
@Path("param/typed/jarray")
public JsonArray sendArray(
final JsonArray json) {
System.out.println(json);
return json;
}
@POST
@Path("param/typed/request")
public String sendObj(
final HttpServerRequest request,
final HttpServerResponse response
) {
System.out.println(request);
System.out.println(response);
return "Hello, request/response.";
}
}
......
[ ZERO ] ( 3 Event ) The endpoint up.god.micro.params.TypedExecutor scanned 3 events of Event, \
will be mounted to routing system.
......
[ ZERO ] ( Uri Register ) "/api/param/typed/jarray" has been deployed by ZeroHttpAgent, Options = Route...
[ ZERO ] ( Uri Register ) "/api/param/typed/json" has been deployed by ZeroHttpAgent, Options = Route...
[ ZERO ] ( Uri Register ) "/api/param/typed/request" has been deployed by ZeroHttpAgent, Options = Route...
......
URL : http://localhost:6083/api/param/typed/json
Method : POST
Request :
{
"username":"Lang.Yu",
"password":"11111111"
}
Response :
{
"data": {
"username": "Lang.Yu",
"password": "11111111"
}
}
URL: http://localhost:6083/api/param/typed/jarray
Method: POST
Request :
[{
"username":"Lang.Yu",
"password":"111111111"
},{
"username":"Lang.Yu1",
"email":"[email protected]"
}]
Response :
{
"data": [
{
"username": "Lang.Yu",
"password": "111111111"
},
{
"username": "Lang.Yu1",
"email": "[email protected]"
}
]
}
URL: http://localhost:6083/api/param/typed/jarray
Method: POST
Request :
{
"username":"request"
}
Response :
{
"data": "Hello, request/response."
}
Here you could see the object output in console and they are not null as following:
io.vertx.ext.web.impl.HttpServerRequestWrapper@7fce20b3
io.vertx.core.http.impl.HttpServerResponseImpl@117977a3
This tutorial describe the typed parameters by zero system default supported, in this situation you should know how to use typed parameters in your project.