Example usage for org.springframework.data.rest.webmvc IncomingRequest isJsonPatchRequest

List of usage examples for org.springframework.data.rest.webmvc IncomingRequest isJsonPatchRequest

Introduction

In this page you can find the example usage for org.springframework.data.rest.webmvc IncomingRequest isJsonPatchRequest.

Prototype

public boolean isJsonPatchRequest() 

Source Link

Document

Returns whether the request is a PATCH request with a payload of type RestMediaTypes#JSON_PATCH_JSON .

Usage

From source file:org.springframework.data.rest.webmvc.config.JsonPatchHandler.java

/**
 * Applies the body of the given {@link IncomingRequest} as patch on the given target object.
 * /* w  w  w.  ja  v  a2  s  .c  o m*/
 * @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);
    }
}