title: how not to consider @NotBlank in some methods
body: <p>I'm doing a restful app in Spring boot,jpa,mysql. I have annoted some of my model fields @NotBlank to print an error in the creation of an object if those fields are blank.
  Now when i'm updating, I don't want to get that error if I don't set some fields in my json body.My goal is to update just the fields which are present.
  So I want to know if there is a way not to consider an @NotBlank in my updating method.</p>
  
  <p>This is the code source :</p>
  
  <p>For the Entity</p>
  
  <pre><code>public class Note implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  
  @NotBlank(name)
  private String title;
  
  @NotBlank
  private String content;
  //Getters and Setters
  
  } 
  </code></pre>
  
  <p>The controller</p>
  
  <pre><code>@RestController
  @RequestMapping("/api")
  public class NoteController {
  
  @Autowired
  NoteRepository noteRepository;
  
  // Create a new Note
  @PostMapping("/notes")
  public Note createNote(@Valid @RequestBody Note note) {
      return noteRepository.save(note);
  }
  
  // Update a Note
  
  @PutMapping("/notes/{id}")
  public Note partialUpdateNote(@PathVariable(value = "id") Long noteId,
                                           @RequestBody Note noteDetails) {          
      Note note = noteRepository.findById(noteId)
              .orElseThrow(() -&gt; new ResourceNotFoundException("Note", "id",   noteId));
      //copyNonNullProperties(noteDetails, note);
  
      if(note.getTitle()!= null) {
          note.setTitle(noteDetails.getTitle());
      }else {
          note.setTitle(note.getTitle());
      }
  
      if(note.getContent()!= null) {
          note.setContent(noteDetails.getContent());
      }else {
          note.setContent(note.getContent());
      }
      Note updatedNote = noteRepository.save(note);
      return updatedNote;
  }
  
  // Delete a Note
  @DeleteMapping("/notes/{id}")
  public ResponseEntity&lt;?&gt; deleteNote(@PathVariable(value = "id") Long noteId) {
      Note note = noteRepository.findById(noteId)
              .orElseThrow(() -&gt; new ResourceNotFoundException("Note", "id", noteId));
  
      noteRepository.delete(note);
  
      return ResponseEntity.ok().build();
  }
  }
  </code></pre>
  
  <p>ResourceNotFoundException is the class responsible to throws errors.</p>