Example usage for org.springframework.data.rest.webmvc.config JsonPatchHandler JsonPatchHandler

List of usage examples for org.springframework.data.rest.webmvc.config JsonPatchHandler JsonPatchHandler

Introduction

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

Prototype

public JsonPatchHandler(ObjectMapper mapper, DomainObjectReader reader) 

Source Link

Document

Creates a new JsonPatchHandler with the given ObjectMapper and DomainObjectReader .

Usage

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

@Before
public void setUp() {

    MongoMappingContext context = new MongoMappingContext();
    context.getPersistentEntity(User.class);

    PersistentEntities entities = new PersistentEntities(Arrays.asList(context));

    Associations associations = new Associations(mappings, mock(RepositoryRestConfiguration.class));

    this.handler = new JsonPatchHandler(new ObjectMapper(), new DomainObjectReader(entities, associations));

    Address address = new Address();
    address.street = "Foo";
    address.zipCode = "Bar";

    this.user = new User();
    this.user.firstname = "Oliver";
    this.user.lastname = "Gierke";
    this.user.address = address;
}

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

private Object readPatch(IncomingRequest request, ObjectMapper mapper, Object existingObject) {

    try {/*from w w  w. jav  a  2 s .c  om*/

        JsonPatchHandler handler = new JsonPatchHandler(mapper, reader);
        return handler.apply(request, existingObject);

    } catch (Exception o_O) {

        if (o_O instanceof HttpMessageNotReadableException) {
            throw (HttpMessageNotReadableException) o_O;
        }

        throw new HttpMessageNotReadableException(String.format(ERROR_MESSAGE, existingObject.getClass()), o_O);
    }
}

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

private Object readPutForUpdate(IncomingRequest request, ObjectMapper mapper, Object existingObject) {

    try {//from  w w w  .java  2s .c o  m

        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);
    }
}