This week's book giveaway is in the Testing forum.
We're giving away four copies of The Way of the Web Tester: A Beginner's Guide to Automating Tests and have Jonathan Rasmusson on-line!
See this thread for details.
Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Constraint validation on RESTful resource method in Jersey project

Vani Kumar
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am newbie to Jersey and Bean Validation and trying to do custom constraint validation on resource method form parameter.

I have the resource method as

public User findPostUser(@IdInterface @FormParam("userId") String fUserId) throws
return userMap().get(Integer.valueOf(fUserId));
return null;

Constraint Annotation as

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
import java.lang.annotation.RetentionPolicy;
import javax.validation.Constraint;
import javax.validation.Payload;

@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER })
@Constraint(validatedBy = UserIdValidator.class)
public @interface IdInterface {
String message() default "{}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};

Constraint Validator as

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
public class IdValidator implements ConstraintValidator<IdInterface, String> {
public void initialize(IdInterface useridinterface) {

public boolean isValid(String value, ConstraintValidatorContext context) {
System.out.println("object is null");
return true;
return false;

I added Jersey-bean-validator jar file to lib folder of Tomcat web project.

I don't see the FormParam is being validated.

Is the above code sufficient to do bean validation with Jersey-bean-validatorl jar and Jersey with Tomcat.

Please let me know if i am missing something here.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic