Javax.Validation - allow null but validate if the value is not

I am using javax Validation.constraints and I want to validate input but allow it to be null, my POJO:

public class somePOJO{

@NotNull

@Size(min =2, max=50)

@Pattern(regexp="^[A-Za-z \\s\\-]*$")

private String country;

@Size(min =2,max=50)

@Pattern(regexp="^[A-Za-z \\s\\-]*$")

private String state;

//gettes, setters.....

}

I want to validate state for example with @Pattern and @size only if it not null.

Is there a way to do it with using custom annotations?...

Read More »

By: StackOverFlow - Thursday, 8 November

Related Posts