example patch request

Example: example patch request java

@PatchMapping(path = "/{id}", consumes = "application/json-patch+json")public ResponseEntity<Customer> updateCustomer(@PathVariable String id, @RequestBody JsonPatch patch) {    try {        Customer customer = customerService.findCustomer(id).orElseThrow(CustomerNotFoundException::new);        Customer customerPatched = applyPatchToCustomer(patch, customer);        customerService.updateCustomer(customerPatched);        return ResponseEntity.ok(customerPatched);    } catch (JsonPatchException | JsonProcessingException e) {        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();    } catch (CustomerNotFoundException e) {        return ResponseEntity.status(HttpStatus.NOT_FOUND).build();    }}

Tags:

Java Example