• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Constraint validation on RESTful resource method in Jersey project

Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 "{com.rest.validation.IdInterface.message}";
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.
    Bookmark Topic Watch Topic
  • New Topic