Example usage for org.springframework.data.web JsonProjectingMethodInterceptorFactory JsonProjectingMethodInterceptorFactory

List of usage examples for org.springframework.data.web JsonProjectingMethodInterceptorFactory JsonProjectingMethodInterceptorFactory

Introduction

In this page you can find the example usage for org.springframework.data.web JsonProjectingMethodInterceptorFactory JsonProjectingMethodInterceptorFactory.

Prototype

public JsonProjectingMethodInterceptorFactory(MappingProvider mappingProvider) 

Source Link

Document

Creates a new JsonProjectingMethodInterceptorFactory using the given ObjectMapper .

Usage

From source file:org.springframework.data.web.JsonProjectingMethodInterceptorFactoryUnitTests.java

@Before
public void setUp() {

    String json = "{\"firstname\" : \"Dave\", "//
            + "\"address\" : { \"zipCode\" : \"01097\", \"city\" : \"Dresden\" }," //
            + "\"addresses\" : [ { \"zipCode\" : \"01097\", \"city\" : \"Dresden\" }]" + " }";

    SpelAwareProxyProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();

    MappingProvider mappingProvider = new JacksonMappingProvider(new ObjectMapper());
    projectionFactory.registerMethodInvokerFactory(new JsonProjectingMethodInterceptorFactory(mappingProvider));

    this.projectionFactory = projectionFactory;
    this.customer = projectionFactory.createProjection(Customer.class,
            new ByteArrayInputStream(json.getBytes()));
}

From source file:org.springframework.data.web.ProjectingJackson2HttpMessageConverter.java

/**
 * Creates a new {@link SpelAwareProxyProjectionFactory} with the {@link JsonProjectingMethodInterceptorFactory}
 * registered for the given {@link ObjectMapper}.
 * /*ww w.  j  a v a 2 s .  com*/
 * @param mapper must not be {@literal null}.
 * @return
 */
private static SpelAwareProxyProjectionFactory initProjectionFactory(ObjectMapper mapper) {

    Assert.notNull(mapper, "ObjectMapper must not be null!");

    SpelAwareProxyProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
    projectionFactory.registerMethodInvokerFactory(
            new JsonProjectingMethodInterceptorFactory(new JacksonMappingProvider(mapper)));

    return projectionFactory;
}