Garmaine Staff asked 1 year ago

I’m new here and I have a problem with validation of my bean . I’m using Quarkus with MongoDB and when I try to run a create rest api, with @Valid before request bean, I expect an exception if I want to create a document with null field (obviously I use @NotNull in entity), but document is created without field. This is my code:

Car.java

@MongoEntity(collection="cars")

public class Car extends PanacheMongoEntityBase {

@BsonId
private long id;
@NotNull
private String carName;
@NotNull
@Size(min = 1, max = 3)
private String code;

// get and set

}

CarResource.java

@Path("/cars")

@Consumes("application/json")

@Produces("application/json")

public class CarResource {

@GET
public List<Car> list() {
    return Car.listAll();
}

@GET
@Path("/{id}")
public Car get(long id) {
    return Car.findById(id);
}

@POST
public Response create(@Valid Car car) {
    car.persist();
    return Response.status(201).build();
}

I have same problem with @Size annotation, because I can create a “code” field with more characters than 3.

And more..is there an annotation like @Indexed(unique = true)? I want an unique field for my app.

Thank you in advice.