2626import org .springframework .data .domain .Page ;
2727import org .springframework .data .domain .PageRequest ;
2828import org .springframework .data .domain .Pageable ;
29+ import org .springframework .hateoas .EntityModel ;
2930import org .springframework .hateoas .IanaLinkRelations ;
3031import org .springframework .hateoas .Link ;
3132import org .springframework .hateoas .LinkRelation ;
32- import org .springframework .hateoas .PagedResources ;
33- import org .springframework .hateoas .PagedResources .PageMetadata ;
34- import org .springframework .hateoas .Resource ;
35- import org .springframework .hateoas .ResourceAssembler ;
36- import org .springframework .hateoas .ResourceSupport ;
33+ import org .springframework .hateoas .PagedModel ;
34+ import org .springframework .hateoas .PagedModel .PageMetadata ;
35+ import org .springframework .hateoas .RepresentationModel ;
3736import org .springframework .hateoas .UriTemplate ;
38- import org .springframework .hateoas .core .EmbeddedWrapper ;
39- import org .springframework .hateoas .core .EmbeddedWrappers ;
37+ import org .springframework .hateoas .server .RepresentationModelAssembler ;
38+ import org .springframework .hateoas .server .core .EmbeddedWrapper ;
39+ import org .springframework .hateoas .server .core .EmbeddedWrappers ;
4040import org .springframework .lang .Nullable ;
4141import org .springframework .util .Assert ;
4242import org .springframework .web .servlet .support .ServletUriComponentsBuilder ;
5151 * @author Nick Williams
5252 * @author Marcel Overdijk
5353 */
54- public class PagedResourcesAssembler <T > implements ResourceAssembler <Page <T >, PagedResources < Resource <T >>> {
54+ public class PagedResourcesAssembler <T > implements RepresentationModelAssembler <Page <T >, PagedModel < EntityModel <T >>> {
5555
5656 private final HateoasPageableHandlerMethodArgumentResolver pageableResolver ;
5757 private final Optional <UriComponents > baseUri ;
@@ -62,7 +62,7 @@ public class PagedResourcesAssembler<T> implements ResourceAssembler<Page<T>, Pa
6262 /**
6363 * Creates a new {@link PagedResourcesAssembler} using the given {@link PageableHandlerMethodArgumentResolver} and
6464 * base URI. If the former is {@literal null}, a default one will be created. If the latter is {@literal null}, calls
65- * to {@link #toResource (Page)} will use the current request's URI to build the relevant previous and next links.
65+ * to {@link #toModel (Page)} will use the current request's URI to build the relevant previous and next links.
6666 *
6767 * @param resolver can be {@literal null}.
6868 * @param baseUri can be {@literal null}.
@@ -89,12 +89,12 @@ public void setForceFirstAndLastRels(boolean forceFirstAndLastRels) {
8989
9090 /*
9191 * (non-Javadoc)
92- * @see org.springframework.hateoas.ResourceAssembler#toResource (java.lang.Object)
92+ * @see org.springframework.hateoas.server.RepresentationModelAssembler#toModel (java.lang.Object)
9393 */
9494 @ Override
9595 @ SuppressWarnings ("null" )
96- public PagedResources < Resource <T >> toResource (Page <T > entity ) {
97- return toResource (entity , it -> new Resource <>(it ));
96+ public PagedModel < EntityModel <T >> toModel (Page <T > entity ) {
97+ return toModel (entity , it -> new EntityModel <>(it ));
9898 }
9999
100100 /**
@@ -106,8 +106,8 @@ public PagedResources<Resource<T>> toResource(Page<T> entity) {
106106 * @param selfLink must not be {@literal null}.
107107 * @return
108108 */
109- public PagedResources < Resource <T >> toResource (Page <T > page , Link selfLink ) {
110- return toResource (page , it -> new Resource <>(it ), selfLink );
109+ public PagedModel < EntityModel <T >> toModel (Page <T > page , Link selfLink ) {
110+ return toModel (page , it -> new EntityModel <>(it ), selfLink );
111111 }
112112
113113 /**
@@ -118,8 +118,9 @@ public PagedResources<Resource<T>> toResource(Page<T> page, Link selfLink) {
118118 * @param assembler must not be {@literal null}.
119119 * @return
120120 */
121- public <R extends ResourceSupport > PagedResources <R > toResource (Page <T > page , ResourceAssembler <T , R > assembler ) {
122- return createResource (page , assembler , Optional .empty ());
121+ public <R extends RepresentationModel <?>> PagedModel <R > toModel (Page <T > page ,
122+ RepresentationModelAssembler <T , R > assembler ) {
123+ return createModel (page , assembler , Optional .empty ());
123124 }
124125
125126 /**
@@ -132,12 +133,12 @@ public <R extends ResourceSupport> PagedResources<R> toResource(Page<T> page, Re
132133 * @param link must not be {@literal null}.
133134 * @return
134135 */
135- public <R extends ResourceSupport > PagedResources <R > toResource (Page <T > page , ResourceAssembler < T , R > assembler ,
136- Link link ) {
136+ public <R extends RepresentationModel <?>> PagedModel <R > toModel (Page <T > page ,
137+ RepresentationModelAssembler < T , R > assembler , Link link ) {
137138
138139 Assert .notNull (link , "Link must not be null!" );
139140
140- return createResource (page , assembler , Optional .of (link ));
141+ return createModel (page , assembler , Optional .of (link ));
141142 }
142143
143144 /**
@@ -148,8 +149,8 @@ public <R extends ResourceSupport> PagedResources<R> toResource(Page<T> page, Re
148149 * @return
149150 * @since 2.0
150151 */
151- public PagedResources <?> toEmptyResource (Page <?> page , Class <?> type ) {
152- return toEmptyResource (page , type , Optional .empty ());
152+ public PagedModel <?> toEmptyModel (Page <?> page , Class <?> type ) {
153+ return toEmptyModel (page , type , Optional .empty ());
153154 }
154155
155156 /**
@@ -161,11 +162,11 @@ public PagedResources<?> toEmptyResource(Page<?> page, Class<?> type) {
161162 * @return
162163 * @since 1.11
163164 */
164- public PagedResources <?> toEmptyResource (Page <?> page , Class <?> type , Link link ) {
165- return toEmptyResource (page , type , Optional .of (link ));
165+ public PagedModel <?> toEmptyModel (Page <?> page , Class <?> type , Link link ) {
166+ return toEmptyModel (page , type , Optional .of (link ));
166167 }
167168
168- private PagedResources <?> toEmptyResource (Page <?> page , Class <?> type , Optional <Link > link ) {
169+ private PagedModel <?> toEmptyModel (Page <?> page , Class <?> type , Optional <Link > link ) {
169170
170171 Assert .notNull (page , "Page must must not be null!" );
171172 Assert .isTrue (!page .hasContent (), "Page must not have any content!" );
@@ -177,7 +178,7 @@ private PagedResources<?> toEmptyResource(Page<?> page, Class<?> type, Optional<
177178 EmbeddedWrapper wrapper = wrappers .emptyCollectionOf (type );
178179 List <EmbeddedWrapper > embedded = Collections .singletonList (wrapper );
179180
180- return addPaginationLinks (new PagedResources <>(embedded , metadata ), page , link );
181+ return addPaginationLinks (new PagedModel <>(embedded , metadata ), page , link );
181182 }
182183
183184 /**
@@ -188,34 +189,34 @@ private PagedResources<?> toEmptyResource(Page<?> page, Class<?> type, Optional<
188189 * @param page the original page handed to the assembler, must not be {@literal null}.
189190 * @return must not be {@literal null}.
190191 */
191- protected <R extends ResourceSupport , S > PagedResources <R > createPagedResource (List <R > resources ,
192+ protected <R extends RepresentationModel <?> , S > PagedModel <R > createPagedModel (List <R > resources ,
192193 PageMetadata metadata , Page <S > page ) {
193194
194195 Assert .notNull (resources , "Content resources must not be null!" );
195196 Assert .notNull (metadata , "PageMetadata must not be null!" );
196197 Assert .notNull (page , "Page must not be null!" );
197198
198- return new PagedResources <>(resources , metadata );
199+ return new PagedModel <>(resources , metadata );
199200 }
200201
201- private <S , R extends ResourceSupport > PagedResources <R > createResource (Page <S > page ,
202- ResourceAssembler <S , R > assembler , Optional <Link > link ) {
202+ private <S , R extends RepresentationModel <?>> PagedModel <R > createModel (Page <S > page ,
203+ RepresentationModelAssembler <S , R > assembler , Optional <Link > link ) {
203204
204205 Assert .notNull (page , "Page must not be null!" );
205206 Assert .notNull (assembler , "ResourceAssembler must not be null!" );
206207
207208 List <R > resources = new ArrayList <>(page .getNumberOfElements ());
208209
209210 for (S element : page ) {
210- resources .add (assembler .toResource (element ));
211+ resources .add (assembler .toModel (element ));
211212 }
212213
213- PagedResources <R > resource = createPagedResource (resources , asPageMetadata (page ), page );
214+ PagedModel <R > resource = createPagedModel (resources , asPageMetadata (page ), page );
214215
215216 return addPaginationLinks (resource , page , link );
216217 }
217218
218- private <R > PagedResources <R > addPaginationLinks (PagedResources <R > resources , Page <?> page , Optional <Link > link ) {
219+ private <R > PagedModel <R > addPaginationLinks (PagedModel <R > resources , Page <?> page , Optional <Link > link ) {
219220
220221 UriTemplate base = getUriTemplate (link );
221222
0 commit comments