Skip to content

Commit ac2d50d

Browse files
committed
DATAREST-1251 - PersistentEntityProjector now uses lambdas instead of anonymous inner classes.
1 parent 70eafa5 commit ac2d50d

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/PersistentEntityProjector.java

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*/
1616
package org.springframework.data.rest.webmvc.support;
1717

18-
import org.springframework.core.convert.converter.Converter;
18+
import java.util.function.Function;
19+
1920
import org.springframework.data.projection.ProjectionFactory;
2021
import org.springframework.data.rest.core.mapping.ResourceMappings;
2122
import org.springframework.data.rest.core.projection.ProjectionDefinitions;
@@ -59,14 +60,7 @@ public PersistentEntityProjector(ProjectionDefinitions projectionDefinitions, Pr
5960
* @see org.springframework.data.rest.webmvc.support.Projector#project(java.lang.Object)
6061
*/
6162
public Object project(Object source) {
62-
63-
return projectWithDefault(source, new Converter<Object, Object>() {
64-
65-
@Override
66-
public Object convert(Object source) {
67-
return source;
68-
}
69-
});
63+
return projectWithDefault(source, Function.identity());
7064
}
7165

7266
/*
@@ -75,34 +69,27 @@ public Object convert(Object source) {
7569
*/
7670
@Override
7771
public Object projectExcerpt(Object source) {
78-
79-
return projectWithDefault(source, new Converter<Object, Object>() {
80-
81-
@Override
82-
public Object convert(Object source) {
83-
return PersistentEntityProjector.super.projectExcerpt(source);
84-
}
85-
});
72+
return projectWithDefault(source, PersistentEntityProjector.super::projectExcerpt);
8673
}
8774

8875
/**
89-
* Creates the projection for the given source instance falling back to the given {@link Converter} if no explicit
76+
* Creates the projection for the given source instance falling back to the given {@link Function} if no explicit
9077
* projection is selected.
9178
*
9279
* @param source must not be {@literal null}.
9380
* @param converter must not be {@literal null}.
9481
* @return
9582
*/
96-
private Object projectWithDefault(Object source, Converter<Object, Object> converter) {
83+
private Object projectWithDefault(Object source, Function<Object, Object> converter) {
9784

9885
Assert.notNull(source, "Projection source must not be null!");
9986
Assert.notNull(converter, "Converter must not be null!");
10087

10188
if (!StringUtils.hasText(projection)) {
102-
return converter.convert(source);
89+
return converter.apply(source);
10390
}
10491

10592
Class<?> projectionType = definitions.getProjectionType(source.getClass(), projection);
106-
return projectionType == null ? converter.convert(source) : factory.createProjection(projectionType, source);
93+
return projectionType == null ? converter.apply(source) : factory.createProjection(projectionType, source);
10794
}
10895
}

0 commit comments

Comments
 (0)