title: Method based validation using Spring validator interface
body: <p>I am developing a service using Spring. As a part of it, I have a controller class which deals with one particular object(Let us assume it is Obj1). I have 3 methods in the controller class. </p>
  
  <ol>
  <li>One method to fetch all Obj1s from database(needs no validation).</li>
  <li>One method to save a new Obj1 to the database (In this case the ID field in Obj1 should be 0).</li>
  <li>One more method to update an existing Obj1(In this case the ID field should be greater than 0).</li>
  </ol>
  
  <p>I have a class that implements <strong>validator</strong> interface. I use this class to perform all the validations.Let us call it Obj1Validator.</p>
  
  <p>How can I perform validation based on the controller method called in the class that implements validator interface?</p>
  
  <p>I know that I can <strong>annotate</strong> the object properties and use <strong>groups</strong> and <strong>validated</strong> annotation to perform this kind of validation instead of doing it using <strong>validator</strong> interface. Or I can use partial annotation and partial validator approach.</p>
  
  <p>However, I have tried to explain my validation requirement using a simple scenario though in reality the validation I need to perform is much more complex and hence I have to use Validator interface and not the annotation based validation.</p>
  
  <p>Can some one tell me how can I handle this scenario? Or is there any way to get the group mentioned in <strong>@validated(group="x")</strong> inside <strong>Obj1Validator</strong>, in which case I can easily perform method based validation.</p>