Skip to the content.

JSR303, @NotNull

From this chapter, we’ll ignore the console output because in previous tutorials, you have known most of zero output logs. In many business scenarios, you need following features in your system:

From this chapter we’ll focus on JSR303, Bean Validation part, zero has used Hibernate Validator to support JSR303 validation, except this specification, zero system created another advanced validation feature to verify your json data format, it’s common used in different Body Request here.

Demo projects:

Rules:

  1. JSR303 is only supported in Agent component in zero system, it means that after you have send the message to event bus, the JSR303 will be effectiveness.
  2. When you write the code with the Interface Style ( Will introduce in forward tutorials ), JSR303 will not support this kind of situation.
  3. For @BodyParam, it also impact Agent component only, but could support Interface Style instead of JSR303 and could provide more useful validations.

1. Source Code

package up.god.micro.validation;

import io.vertx.up.annotations.EndPoint;

import javax.validation.constraints.NotNull;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

@EndPoint
@Path("/api/jsr303/")
public class NotNullActor {

    @GET
    @Path("/notnull/query")
    public String testValid(
            @NotNull
            @PathParam("name") final String name) {
        return "Hello, " + name;
    }
}

2. Testing

URL : http://localhost:6083/api/jsr303/notnull/query

Method : GET

Response : ( Status = 400 )

{
    "code": -60000,
    "message": "[ERR-60000] (Validator) Web Exception occus: (400) - Request validation handler, class = class up.god.micro.validation.NotNullActor, method = public java.lang.String up.god.micro.validation.NotNullActor.testValid(java.lang.String), message = must not be null.",
    "info": "must not be null"
}

3. Summary

From above response information, you should see the validation failure in zero system, please read following comments for each json node meanings: