Reputation: 363
I have some class with string fields inside it
public class Variable {
private String id;
private String name;
}
My goal is to have String name
<= 256 characters and regexp ^[a-zA-Z0-9_]*$
. Can I do it somehow using Jackson annotations?
Upvotes: 0
Views: 1829
Reputation: 3945
You can try it like this:
import javax.validation.constraints.Pattern;
public class Variable {
private String id;
@Pattern(regexp = "^[a-zA-Z0-9_]{1,256}$")
private String name;
public Variable() {
}
// getter/setter ..
}
Upvotes: 1