Skip to content

Commit b49d1b7

Browse files
committed
Polishing.
Un-deprecate constructor. Rearrange method arguments to match parameter significance. Reformat code, replace space indents with tabs. Original pull request: #2403.
1 parent d1e27b5 commit b49d1b7

File tree

3 files changed

+40
-32
lines changed

3 files changed

+40
-32
lines changed

Diff for: src/main/java/org/springframework/data/web/JsonProjectingMethodInterceptorFactory.java

+29-24
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import org.aopalliance.intercept.MethodInterceptor;
3131
import org.aopalliance.intercept.MethodInvocation;
32+
3233
import org.springframework.core.ResolvableType;
3334
import org.springframework.core.annotation.AnnotationUtils;
3435
import org.springframework.data.projection.Accessor;
@@ -45,8 +46,8 @@
4546
import com.jayway.jsonpath.ParseContext;
4647
import com.jayway.jsonpath.PathNotFoundException;
4748
import com.jayway.jsonpath.TypeRef;
48-
import com.jayway.jsonpath.spi.mapper.MappingProvider;
4949
import com.jayway.jsonpath.spi.json.JsonProvider;
50+
import com.jayway.jsonpath.spi.mapper.MappingProvider;
5051

5152
/**
5253
* {@link MethodInterceptorFactory} to create a {@link MethodInterceptor} that will
@@ -61,34 +62,38 @@ public class JsonProjectingMethodInterceptorFactory implements MethodInterceptor
6162

6263
private final ParseContext context;
6364

64-
/**
65-
* Creates a new {@link JsonProjectingMethodInterceptorFactory} using the given {@link MappingProvider} and {@link JsonProvider}.
66-
*
67-
* @param mappingProvider must not be {@literal null}.
68-
* @param jsonProvider must not be {@literal null}.
69-
*/
70-
public JsonProjectingMethodInterceptorFactory(MappingProvider mappingProvider, JsonProvider jsonProvider) {
71-
72-
Assert.notNull(mappingProvider, "MappingProvider must not be null!");
73-
Assert.notNull(jsonProvider, "JsonProvider must not be null!");
74-
75-
Configuration configuration = Configuration.builder()//
76-
.options(Option.ALWAYS_RETURN_LIST)//
77-
.mappingProvider(mappingProvider)//
78-
.jsonProvider(jsonProvider)//
79-
.build();
80-
81-
this.context = JsonPath.using(configuration);
82-
}
83-
8465
/**
85-
* Creates a new {@link JsonProjectingMethodInterceptorFactory} using the given {@link MappingProvider}.
66+
* Creates a new {@link JsonProjectingMethodInterceptorFactory} using the default {@link JsonProvider} and the given
67+
* {@link MappingProvider}.
8668
*
8769
* @param mappingProvider must not be {@literal null}.
70+
* @see Configuration#defaultConfiguration()
71+
* @see Configuration#jsonProvider()
8872
*/
89-
@Deprecated
9073
public JsonProjectingMethodInterceptorFactory(MappingProvider mappingProvider) {
91-
this(mappingProvider, Configuration.defaultConfiguration().jsonProvider());
74+
this(Configuration.defaultConfiguration().jsonProvider(), mappingProvider);
75+
}
76+
77+
/**
78+
* Creates a new {@link JsonProjectingMethodInterceptorFactory} using the given {@link JsonProvider} and
79+
* {@link MappingProvider}.
80+
*
81+
* @param jsonProvider must not be {@literal null}.
82+
* @param mappingProvider must not be {@literal null}.
83+
* @since 2.5.3
84+
*/
85+
public JsonProjectingMethodInterceptorFactory(JsonProvider jsonProvider, MappingProvider mappingProvider) {
86+
87+
Assert.notNull(jsonProvider, "JsonProvider must not be null!");
88+
Assert.notNull(mappingProvider, "MappingProvider must not be null!");
89+
90+
Configuration configuration = Configuration.builder()//
91+
.options(Option.ALWAYS_RETURN_LIST) //
92+
.jsonProvider(jsonProvider) //
93+
.mappingProvider(mappingProvider) //
94+
.build();
95+
96+
this.context = JsonPath.using(configuration);
9297
}
9398

9499
/*

Diff for: src/main/java/org/springframework/data/web/ProjectingJackson2HttpMessageConverter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.lang.reflect.Type;
2020
import java.util.Map;
2121

22-
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
2322
import org.springframework.beans.BeansException;
2423
import org.springframework.beans.factory.BeanClassLoaderAware;
2524
import org.springframework.beans.factory.BeanFactory;
@@ -37,6 +36,7 @@
3736
import org.springframework.util.ConcurrentReferenceHashMap;
3837

3938
import com.fasterxml.jackson.databind.ObjectMapper;
39+
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
4040
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
4141

4242
/**
@@ -85,8 +85,8 @@ private static SpelAwareProxyProjectionFactory initProjectionFactory(ObjectMappe
8585
Assert.notNull(mapper, "ObjectMapper must not be null!");
8686

8787
SpelAwareProxyProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
88-
projectionFactory
89-
.registerMethodInvokerFactory(new JsonProjectingMethodInterceptorFactory(new JacksonMappingProvider(mapper), new JacksonJsonProvider(mapper)));
88+
projectionFactory.registerMethodInvokerFactory(new JsonProjectingMethodInterceptorFactory(
89+
new JacksonJsonProvider(mapper), new JacksonMappingProvider(mapper)));
9090

9191
return projectionFactory;
9292
}

Diff for: src/test/java/org/springframework/data/web/JsonProjectingMethodInterceptorFactoryUnitTests.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
import static org.assertj.core.api.Assertions.*;
1919

20-
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
21-
import com.jayway.jsonpath.spi.json.JsonProvider;
2220
import lombok.AllArgsConstructor;
2321
import lombok.Data;
2422
import lombok.NoArgsConstructor;
@@ -30,10 +28,13 @@
3028

3129
import org.junit.jupiter.api.BeforeEach;
3230
import org.junit.jupiter.api.Test;
31+
3332
import org.springframework.data.projection.ProjectionFactory;
3433
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
3534

3635
import com.fasterxml.jackson.databind.ObjectMapper;
36+
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
37+
import com.jayway.jsonpath.spi.json.JsonProvider;
3738
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
3839
import com.jayway.jsonpath.spi.mapper.MappingProvider;
3940

@@ -60,9 +61,11 @@ void setUp() {
6061

6162
SpelAwareProxyProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
6263

63-
MappingProvider mappingProvider = new JacksonMappingProvider(new ObjectMapper());
64-
JsonProvider jsonProvider = new JacksonJsonProvider(new ObjectMapper());
65-
projectionFactory.registerMethodInvokerFactory(new JsonProjectingMethodInterceptorFactory(mappingProvider, jsonProvider));
64+
ObjectMapper objectMapper = new ObjectMapper();
65+
MappingProvider mappingProvider = new JacksonMappingProvider(objectMapper);
66+
JsonProvider jsonProvider = new JacksonJsonProvider(objectMapper);
67+
projectionFactory
68+
.registerMethodInvokerFactory(new JsonProjectingMethodInterceptorFactory(jsonProvider, mappingProvider));
6669

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

0 commit comments

Comments
 (0)