I have an REST endpoint, which takes an object in the request body and a request parameter. When the request parameter is passed, I need to validate all the attributes of the object, if not the parameter takes the default value assigned and only 2 attributes needs to be validated. The path needs to be same for both the case. How can this be achieved?
Currently I have pattern, length and possibles values check for the objects, validated with the help of annotations.
----- Updating the Class -------
@ValidateParent(parent = "parent ", child= "child")
public class anClass{
@NotNull(groups = {FrstValidator.class, SndValidator.class})
@Pattern(regexp = "^[a-zA-Z]{3}$",
groups = {FrstValidator.class, SndValidator.class})
String str1;
@NotNull(groups = {FrstValidator.class, SndValidator.class})
@Pattern(regexp = "^[a-zA-Z]{3}$",
groups = {FrstValidator.class, SndValidator.class})
String str2;
@Pattern(regexp = "^[a-zA-Z]{10}$",
groups = SndValidator.class)
String child;
@Pattern(regexp = "^[a-zA-Z]{10}$",
groups = SndValidator.class)
String parent;
@Pattern(regexp = "^[a-zA-Z]{10}$",
groups = SndValidator.class)
String str3;
}
ValidateParent
, checks if the parent is also passed when the child is passed in the request body.