private Object readPutForUpdate(IncomingRequest request, ObjectMapper mapper, Object existingObject) { try { JsonPatchHandler handler = new JsonPatchHandler(mapper, reader); JsonNode jsonNode = mapper.readTree(request.getBody()); return handler.applyPut((ObjectNode) jsonNode, existingObject); } catch (Exception o_O) { throw new HttpMessageNotReadableException(String.format(ERROR_MESSAGE, existingObject.getClass()), o_O); } }
/** * Applies the body of the given {@link IncomingRequest} as patch on the given target object. * * @param request must not be {@literal null}. * @param target must not be {@literal null}. * @return * @throws Exception */ public <T> T apply(IncomingRequest request, T target) throws Exception { Assert.notNull(request, "Request must not be null!"); Assert.isTrue(request.isPatchRequest(), "Cannot handle non-PATCH request!"); Assert.notNull(target, "Target must not be null!"); if (request.isJsonPatchRequest()) { return applyPatch(request.getBody(), target); } else { return applyMergePatch(request.getBody(), target); } }
private Object readPutForUpdate(IncomingRequest request, ObjectMapper mapper, Object existingObject, RootResourceInformation information) { try { JsonPatchHandler handler = new JsonPatchHandler(mapper, reader); JsonNode jsonNode = mapper.readTree(request.getBody()); // Here we have required validation mapper.treeToValue(jsonNode, information.getDomainType()); return handler.applyPut((ObjectNode) jsonNode, existingObject); } catch (Exception o_O) { throw new HttpMessageNotReadableException(String.format(ERROR_MESSAGE, existingObject.getClass()), o_O); } }
private Object readPutForUpdate(IncomingRequest request, ObjectMapper mapper, Object existingObject) { try { JsonPatchHandler handler = new JsonPatchHandler(mapper, reader); JsonNode jsonNode = mapper.readTree(request.getBody()); return handler.applyPut((ObjectNode) jsonNode, existingObject); } catch (Exception o_O) { throw new HttpMessageNotReadableException(String.format(ERROR_MESSAGE, existingObject.getClass()), o_O); } }
/** * Applies the body of the given {@link IncomingRequest} as patch on the given target object. * * @param request must not be {@literal null}. * @param target must not be {@literal null}. * @return * @throws Exception */ public <T> T apply(IncomingRequest request, T target) throws Exception { Assert.notNull(request, "Request must not be null!"); Assert.isTrue(request.isPatchRequest(), "Cannot handle non-PATCH request!"); Assert.notNull(target, "Target must not be null!"); if (request.isJsonPatchRequest()) { return applyPatch(request.getBody(), target); } else { return applyMergePatch(request.getBody(), target); } }