15
15
*/
16
16
package org .springframework .data .rest .webmvc .support ;
17
17
18
- import org .springframework .core .convert .converter .Converter ;
18
+ import java .util .function .Function ;
19
+
19
20
import org .springframework .data .projection .ProjectionFactory ;
20
21
import org .springframework .data .rest .core .mapping .ResourceMappings ;
21
22
import org .springframework .data .rest .core .projection .ProjectionDefinitions ;
@@ -59,14 +60,7 @@ public PersistentEntityProjector(ProjectionDefinitions projectionDefinitions, Pr
59
60
* @see org.springframework.data.rest.webmvc.support.Projector#project(java.lang.Object)
60
61
*/
61
62
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 ());
70
64
}
71
65
72
66
/*
@@ -75,34 +69,27 @@ public Object convert(Object source) {
75
69
*/
76
70
@ Override
77
71
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 );
86
73
}
87
74
88
75
/**
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
90
77
* projection is selected.
91
78
*
92
79
* @param source must not be {@literal null}.
93
80
* @param converter must not be {@literal null}.
94
81
* @return
95
82
*/
96
- private Object projectWithDefault (Object source , Converter <Object , Object > converter ) {
83
+ private Object projectWithDefault (Object source , Function <Object , Object > converter ) {
97
84
98
85
Assert .notNull (source , "Projection source must not be null!" );
99
86
Assert .notNull (converter , "Converter must not be null!" );
100
87
101
88
if (!StringUtils .hasText (projection )) {
102
- return converter .convert (source );
89
+ return converter .apply (source );
103
90
}
104
91
105
92
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 );
107
94
}
108
95
}
0 commit comments