@RequestMapping(value="/{bookmarkId}",method=RequestMethod.PUT) public ResponseEntity<Bookmark> editBookmark(@PathVariable(value="username") String username,@PathVariable(value="bookmarkId") int bookmarkId,@RequestBody String json) throws IOException, BookmarkNotFoundException, IllegalAccessException, InvocationTargetException {
  Optional<Bookmark> optional=bookmarksRepository.findByIdAndUserUsername(bookmarkId,username);
  if (optional.isPresent()) {
    ObjectMapper mapper=new ObjectMapper();
    Map<String,String> changeMap=mapper.readValue(json,HashMap.class);
    Bookmark bookmark=optional.get();
    BeanUtils.populate(bookmark,changeMap);
    bookmark=bookmarksRepository.save(bookmark);
    return new ResponseEntity<>(bookmark,HttpStatus.OK);
  }
 else {
    throw new BookmarkNotFoundException("Bookmark not found id = " + bookmarkId);
  }
}

@ RequestMapping ( value = "/{bookmarkId}" , method = RequestMethod . PUT ) public ResponseEntity < Bookmark > editBookmark ( @ PathVariable ( value = "username" ) String username , @ PathVariable ( value = "bookmarkId" ) int bookmarkId , @ RequestBody String json ) throws IOException , BookmarkNotFoundException , IllegalAccessException , InvocationTargetException { Optional < Bookmark > optional = bookmarksRepository . findByIdAndUserUsername ( bookmarkId , username ) ; if ( optional . isPresent ( ) ) { ObjectMapper mapper = new ObjectMapper ( ) ; Map < String , String > changeMap = mapper . readValue ( json , HashMap . class ) ; Bookmark bookmark = optional . get ( ) ; BeanUtils . populate ( bookmark , changeMap ) ; bookmark = bookmarksRepository . save ( bookmark ) ; return new ResponseEntity < > ( bookmark , HttpStatus . OK ) ; } else { throw new BookmarkNotFoundException ( "Bookmark not found id = " + bookmarkId ) ; } }
a method to edit a bookmark .
