is there a way to use javax.validation to validate a variable of type string called colour that needs to have these values only(red, blue, green, pink) using annotations?
you can create an enum
public enum Colors { RED, PINK, YELLOW }
and then in your model, you can validate it like so:
public class Model { @Enumerated(EnumType.STRING) private Colors color; }
which will validate your payload against the enum, given that you have added @Valid in your RestController.