title: How validate an object using @Valid in Spring Boot?
body: <p>I'm working on a Spring Boot project and I'm trying to validate some fields from an object.</p>
  <p>Actually I have an API which accepts parameters. I know I can use <code>@Valid</code> into API declaration like this:</p>
  <pre class="lang-java prettyprint-override"><code>@GetMapping(value=&quot;/...&quot;)
  Object myMethod(@RequestParam(value=&quot;name&quot;) @Size(min = 3) String name)
  </code></pre>
  <p>But I don't want to validate there. I have a &quot;filter&quot; object to validate the values, so I expect something like:</p>
  <p>Controller file</p>
  <pre class="lang-java prettyprint-override"><code>@override
  public Object myMethod(String name){
    @Valid Filter filter = new Filter(name)
  }
  </code></pre>
  <p>And filter is not an entity, only a class with validations tags:</p>
  <pre class="lang-java prettyprint-override"><code>public class Filter
  
    @Size(min = 3)
    private String name;
  
    public Filter(name){
      this.name = name;
    }
  
    // getters and setters
  </code></pre>
  <p>So the idea is to use <code>@Valid</code> creating the object and throws an exception if any validation is not successfull. Is this possible?</p>
  <p>I have found multiple solutions to validate query params, body requests and so on, but not about validate a single object created using <code>new</code>.</p>