title: Spring boot - Combine DTO and form validation
body: <p>I am currently developing an API where I'm using DTO for the first time. So far I've used Spring's form validation with <code>javax.validation</code>.</p>
  
  <p>So my question is if there is a way to combine both DTO and "form" validation. Let me explain myself: lets say I have a service to log in and another to register. In the service to register we have: name, password and email, the 3 of them must be filled. As for the login service, only the email and password must be filled. So we'd have something like:</p>
  
  <pre><code>private String name;
  private String password;
  private String email;
  </code></pre>
  
  <p>Until now, what I did was to create a POJO per request (forms) and then use annotations such as <code>@NotNull</code> but now with DTO in the project I'm in now they just have the same DTO and business object with the same properties and no constraints. </p>
  
  <p>How could I do what I was usually doing? Checking the fields that must be not null in the controller looks a little dirty to me and I can't just put something like <code>@NotNull</code> in the <code>UserDTO</code> because then in the two examples I said I'd have to send also the <code>name</code> when logging in although it's not needed for that service.</p>
  
  <p>So, how could I combine these 2 things? Is this something not possible or there's a better approach?</p>
  
  <p>Thanks.</p>