jax-rs:如何实现自定义参数验证?

时间:2016-05-26 16:47:07

标签: java validation jax-rs bean-validation

我想创建自定义注释(例如@ValidAddress),它将验证对象(使用与JSR303无关的自定义逻辑)并在值无效的情况下抛出异常:

    public Response registerAddress(@ValidAddress Address address)

使用javax.validation.Constraintjavax.validation.ConstraintValidatorsample)很容易实现,但它有一些奇怪的限制:

  1. 注释应该有message / groups / payload参数
  2. isValid无法抛出自定义异常
  3. 问题:

    如何添加自定义注释,该注释将在myFunction($param)从正文中反序列化$param的请求中执行#include<fcntl.h> #include<unistd.h> #include<stdio.h> ... int main(int argc, char * argv[]) { int cp_from = open(argv[1],O_WRONLY); int cp_to = open(argv[2],O_WRONLY|O_CREAT,0777); //make a descriptor for each file int size = lseek(cp_from,0,SEEK_END); //check the size of the first file lseek(cp_from,0,SEEK_SET) //return to the start of the file, don't know if that's needed char *buf = (char*) malloc (size*sizeof(char)); //allocate enough memory to fit all text from 1st file into char array read(cp_from,buf,sizeof(buf)-1); //read from the 1st file to the char array printf("%s",buf); //print the buf close(cp_from); close(cp_to); ...

0 个答案:

没有答案