diff --git a/etc/migrate-to-1.0.sh b/etc/migrate-to-1.0.sh
index 5b71b5ca..ed59d63b 100755
--- a/etc/migrate-to-1.0.sh
+++ b/etc/migrate-to-1.0.sh
@@ -38,6 +38,7 @@ FILES=`find . -name "$FILES_PATTERN"`
EXPRESSION="s/Link\.REL_SELF/IanaLinkRelations.SELF/g;\
s/Link\.REL_PREV/IanaLinkRelations.PREV/g;\
s/Link\.REL_NEXT/IanaLinkRelations.NEXT/g;\
+\
s/hateoas\.EntityLinks/hateoas.server.EntityLinks/g;\
s/hateoas\.JsonPathLinkDiscoverer/hateoas.client.JsonPathLinkDiscoverer/g;\
s/hateoas\.LinkBuilder/hateoas.server.LinkBuilder/g;\
@@ -47,7 +48,11 @@ s/hateoas\.MethodLinkBuilderFactory/hateoas.server.MethodLinkBuilderFactory/g;\
s/hateoas\.RelProvider/hateoas.server.RelProvider/g;\
s/hateoas\.ResourceAssembler/hateoas.server.ResourceAssembler/g;\
s/hateoas\.ResourceProcessor/hateoas.server.ResourceProcessor/g;\
+s/hateoas\.VndErrors/hateoas.mediatype.vnderror.VndErrors/g;\
+s/hateoas\.VndErrors.VndError/hateoas.mediatype.vnderror.VndErrors.VndError/g;\
+\
s/hateoas\.alps/hateoas.mediatype.alps/g;\
+\
s/hateoas\.core\.AbstractEntityLinks/hateoas.server.core.AbstractEntityLinks/g;\
s/hateoas\.core\.AnnotationAttribute/hateoas.server.core.AnnotationAttribute/g;\
s/hateoas\.core\.AnnotationMappingDiscoverer/hateoas.server.core.AnnotationMappingDiscoverer/g;\
@@ -57,7 +62,9 @@ s/hateoas\.core\.EvoInflectorRelProvider/hateoas.server.core.EvoInflectorRelProv
s/hateoas\.core\.JsonPathLinkDiscoverer/hateoas.client.JsonPathLinkDiscoverer/g;\
s/hateoas\.core\.LinkBuilderSupport/hateoas.server.core.LinkBuilderSupport/g;\
s/hateoas\.core\.MethodParameters/hateoas.server.core.MethodParameters/g;\
+\
s/hateoas\.hal/hateoas.mediatype.hal/g;\
+\
s/hateoas\.mvc\.ControllerLinkBuilder/hateoas.server.mvc.WebMvcLinkBuilder/g;\
s/hateoas\.mvc\.ControllerLinkBuilderFactory/hateoas.server.mvc.WebMvcLinkBuilderFactory/g;\
s/hateoas\.mvc\.HeaderLinksResponseEntity/hateoas.server.core.HeaderLinksResponseEntity/g;\
@@ -66,12 +73,35 @@ s/hateoas\.mvc\.ResourceProcessorInvokingHandlerAdapter/hateoas.server.mvc.Resou
s/hateoas\.mvc\.TypeConstrainedMappingJackson2HttpMessageConverter/hateoas.server.mvc.TypeConstrainedMappingJackson2HttpMessageConverter/g;\
s/hateoas\.mvc\.UriComponentsContributor/hateoas.server.mvc.UriComponentsContributor/g;\
s/ControllerLinkBuilderFactory/WebMvcLinkBuilderFactory/g;\
-s/ControllerLinkBuilder/WebMvcLinkBuilder/g;"
+s/ControllerLinkBuilder/WebMvcLinkBuilder/g;\
+\
+s/\([^a-z]\)ResourceProcessorInvokingHandlerAdapter\([ ><,#();\.]\)/\1RepresentationModelProcessorInvokingHandlerAdapter\2/g;\
+s/\([^a-z]\)ResourceProcessorInvoker\([ ><,#();\.]\)/\1RepresentationModelProcessorInvoker\2/g;\
+s/\([^a-z]\)ResourceProcessor\([ ><,#();\.]\)/\1RepresentationModelProcessor\2/g;\
+\
+s/ ResourceAssembler / RepresentationModelAssembler /g;\
+s/\.ResourceAssembler;/.RepresentationModelAssembler;/g;\
+s/ResourceAssembler\([<#]\)/RepresentationModelAssembler\1/g;\
+s/IdentifiableResourceAssemblerSupport/IdentifiableRepresentationModelAssemblerSupport/g;\
+s/toResource(/toModel(/g;\
+s/toResources(/toCollectionModel(/g;\
+\
+s/\([^a-z]\)ResourceSupport\([ ><,#();\.]\)/\1RepresentationModel\2/g;\
+s/\([^a-z]\)PagedResources\([ ><,#();\.]\)/\1PagedModel\2/g;\
+s/\([^a-z]\)Resources\([ ><,#();\.]\)/\1CollectionModel\2/g;\
+s/\([^a-z]\)Resource\([ ><,#();\.]\)/\1EntityModel\2/g;\
+\
+s/linkForSingleResource/linkForItemResource/g;\
+s/linkToSingleResource/linkToItemResource/g;\
+"
+
+#EXPRESSION="s/[\s\.]PagedResources\([;<]\)/.PagedRepresentationModel\1/g;"
for FILE in $FILES
do
echo "Adapting $FILE"
- sed -i "" $EXPRESSION $FILE
+ # echo $EXPRESSION
+ sed -i "" -e "$EXPRESSION" $FILE
done
echo
@@ -81,4 +111,7 @@ echo 'If you have used link relation constants defined in Link (like Link.REL_SE
echo 'codebase, you will have to trigger an organize imports in your IDE to make sure the'
echo 'now referenced IanaLinkRelations gets imported.'
echo
+echo "Also, if you were referring to core Spring's Resource type you might see invalid migrations"
+echo "as there's no way for us to differentiate that from Spring HATEOAS Resource type."
+echo
echo 'After that, review your changes, commit and code on! \ö/'
diff --git a/pom.xml b/pom.xml
index d7381e97..13af771e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -563,7 +563,6 @@
com.jayway.jsonpathjson-path${jsonpath.version}
- true
diff --git a/src/main/asciidoc/migrate-to-1.0.adoc b/src/main/asciidoc/migrate-to-1.0.adoc
index cbc16a79..970a4a59 100644
--- a/src/main/asciidoc/migrate-to-1.0.adoc
+++ b/src/main/asciidoc/migrate-to-1.0.adoc
@@ -10,13 +10,29 @@ There had been an incredible amount of feedback on it and the major version bump
The biggest changes in package structure were driven by the introduction of a hypermedia type registration API to support additional media types in Spring HATEOAS.
This lead to the clear separation of client and server APIs (packages named respectively) as well as media type implementations in the package `mediatype`.
-The easiest way to get your codebase upgraded to the new API is by using the <>.
-Before we jump to that, here are the changes at a quick glance:
+The easiest way to get your code base upgraded to the new API is by using the <>.
+Before we jump to that, here are the changes at a quick glance.
-* `ResourceSupport` now exposes a `Links` instance (over a `List`) as that exposes additional API to concatenate and merge different `Links` instances using various strategies.
+=== Representation models
+
+The `ResourceSupport`/`Resource`/`Resources`/`PagedResources` group of classes never really felt appropriately named.
+After all, these types do not actually manifest resources but rather representation models that can be enriched with hypermedia information and affordances.
+Here's how new names map to the old ones:
+
+* `ResourceSupport` is now `RepresentationModel`
+* `Resource` is now `EntityModel`
+* `Resources` is now `CollectionModel`
+* `PagedResources` is now `PagedModel`
+
+Consequently, `ResourceAssembler` has been renamed to `RepresentationModelAssembler` and its methods `toResource(…)` and `toResources(…)` have been renamed to `toModel(…)` and `toCollectionModel(…)` respectively.
+Also the name changes have been reflected in the classes contained in `TypeReferences`.
+
+* `RepresentationModel.getLinks()` now exposes a `Links` instance (over a `List`) as that exposes additional API to concatenate and merge different `Links` instances using various strategies.
+ Also it has been turned into a self-bound generic type to allow the methods that add links to the instance return the instance itself.
* The `LinkDiscoverer` API has been moved to the `client` package.
-* The `LinkBuilder` API has been moved to the `server` package.
+* The `LinkBuilder` and `EntityLinks` APIs have been moved to the `server` package.
* `ControllerLinkBuilder` has been moved into `server.mvc` and deprecated to be replaced by `WebMvcLinkBuilder`.
+* `VndError` has been moved to the `mediatype.vnderror` package.
[migrate-to-1.0.script]
== The migration script
diff --git a/src/main/java/org/springframework/hateoas/Resources.java b/src/main/java/org/springframework/hateoas/CollectionModel.java
similarity index 74%
rename from src/main/java/org/springframework/hateoas/Resources.java
rename to src/main/java/org/springframework/hateoas/CollectionModel.java
index 61474c5d..b1c65386 100644
--- a/src/main/java/org/springframework/hateoas/Resources.java
+++ b/src/main/java/org/springframework/hateoas/CollectionModel.java
@@ -31,34 +31,34 @@ import com.fasterxml.jackson.annotation.JsonProperty;
* @author Oliver Gierke
* @author Greg Turnquist
*/
-public class Resources extends ResourceSupport implements Iterable {
+public class CollectionModel extends RepresentationModel> implements Iterable {
private final Collection content;
/**
- * Creates an empty {@link Resources} instance.
+ * Creates an empty {@link CollectionModel} instance.
*/
- protected Resources() {
+ protected CollectionModel() {
this(new ArrayList<>());
}
/**
- * Creates a {@link Resources} instance with the given content and {@link Link}s (optional).
+ * Creates a {@link CollectionModel} instance with the given content and {@link Link}s (optional).
*
* @param content must not be {@literal null}.
- * @param links the links to be added to the {@link Resources}.
+ * @param links the links to be added to the {@link CollectionModel}.
*/
- public Resources(Iterable content, Link... links) {
+ public CollectionModel(Iterable content, Link... links) {
this(content, Arrays.asList(links));
}
/**
- * Creates a {@link Resources} instance with the given content and {@link Link}s.
+ * Creates a {@link CollectionModel} instance with the given content and {@link Link}s.
*
* @param content must not be {@literal null}.
- * @param links the links to be added to the {@link Resources}.
+ * @param links the links to be added to the {@link CollectionModel}.
*/
- public Resources(Iterable content, Iterable links) {
+ public CollectionModel(Iterable content, Iterable links) {
Assert.notNull(content, "Content must not be null!");
@@ -71,23 +71,24 @@ public class Resources extends ResourceSupport implements Iterable {
}
/**
- * Creates a new {@link Resources} instance by wrapping the given domain class instances into a {@link Resource}.
+ * Creates a new {@link CollectionModel} instance by wrapping the given domain class instances into a
+ * {@link EntityModel}.
*
* @param content must not be {@literal null}.
* @return
*/
@SuppressWarnings("unchecked")
- public static , S> Resources wrap(Iterable content) {
+ public static , S> CollectionModel wrap(Iterable content) {
Assert.notNull(content, "Content must not be null!");
ArrayList resources = new ArrayList<>();
for (S element : content) {
- resources.add((T) new Resource<>(element));
+ resources.add((T) new EntityModel<>(element));
}
- return new Resources<>(resources);
+ return new CollectionModel<>(resources);
}
/**
@@ -133,7 +134,7 @@ public class Resources extends ResourceSupport implements Iterable {
return false;
}
- Resources> that = (Resources>) obj;
+ CollectionModel> that = (CollectionModel>) obj;
boolean contentEqual = this.content == null ? that.content == null : this.content.equals(that.content);
return contentEqual && super.equals(obj);
diff --git a/src/main/java/org/springframework/hateoas/Resource.java b/src/main/java/org/springframework/hateoas/EntityModel.java
similarity index 77%
rename from src/main/java/org/springframework/hateoas/Resource.java
rename to src/main/java/org/springframework/hateoas/EntityModel.java
index c05d422f..8b6408ed 100644
--- a/src/main/java/org/springframework/hateoas/Resource.java
+++ b/src/main/java/org/springframework/hateoas/EntityModel.java
@@ -23,39 +23,39 @@ import org.springframework.util.Assert;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
/**
- * A simple {@link Resource} wrapping a domain object and adding links to it.
- *
+ * A simple {@link EntityModel} wrapping a domain object and adding links to it.
+ *
* @author Oliver Gierke
* @author Greg Turnquist
*/
-public class Resource extends ResourceSupport {
+public class EntityModel extends RepresentationModel> {
private final T content;
/**
- * Creates an empty {@link Resource}.
+ * Creates an empty {@link EntityModel}.
*/
- protected Resource() {
+ protected EntityModel() {
this.content = null;
}
/**
- * Creates a new {@link Resource} with the given content and {@link Link}s (optional).
- *
+ * Creates a new {@link EntityModel} with the given content and {@link Link}s (optional).
+ *
* @param content must not be {@literal null}.
- * @param links the links to add to the {@link Resource}.
+ * @param links the links to add to the {@link EntityModel}.
*/
- public Resource(T content, Link... links) {
+ public EntityModel(T content, Link... links) {
this(content, Arrays.asList(links));
}
/**
- * Creates a new {@link Resource} with the given content and {@link Link}s.
- *
+ * Creates a new {@link EntityModel} with the given content and {@link Link}s.
+ *
* @param content must not be {@literal null}.
- * @param links the links to add to the {@link Resource}.
+ * @param links the links to add to the {@link EntityModel}.
*/
- public Resource(T content, Iterable links) {
+ public EntityModel(T content, Iterable links) {
Assert.notNull(content, "Content must not be null!");
Assert.isTrue(!(content instanceof Collection), "Content must not be a collection! Use Resources instead!");
@@ -65,7 +65,7 @@ public class Resource extends ResourceSupport {
/**
* Returns the underlying entity.
- *
+ *
* @return the content
*/
@JsonUnwrapped
@@ -73,7 +73,7 @@ public class Resource extends ResourceSupport {
return content;
}
- /*
+ /*
* (non-Javadoc)
* @see org.springframework.hateoas.ResourceSupport#toString()
*/
@@ -82,7 +82,7 @@ public class Resource extends ResourceSupport {
return String.format("Resource { content: %s, %s }", getContent(), super.toString());
}
- /*
+ /*
* (non-Javadoc)
* @see org.springframework.hateoas.ResourceSupport#equals(java.lang.Object)
*/
@@ -97,13 +97,13 @@ public class Resource extends ResourceSupport {
return false;
}
- Resource> that = (Resource>) obj;
+ EntityModel> that = (EntityModel>) obj;
boolean contentEqual = this.content == null ? that.content == null : this.content.equals(that.content);
return contentEqual && super.equals(obj);
}
- /*
+ /*
* (non-Javadoc)
* @see org.springframework.hateoas.ResourceSupport#hashCode()
*/
diff --git a/src/main/java/org/springframework/hateoas/PagedResources.java b/src/main/java/org/springframework/hateoas/PagedModel.java
similarity index 87%
rename from src/main/java/org/springframework/hateoas/PagedResources.java
rename to src/main/java/org/springframework/hateoas/PagedModel.java
index 7f8553ea..68ecf6f4 100644
--- a/src/main/java/org/springframework/hateoas/PagedResources.java
+++ b/src/main/java/org/springframework/hateoas/PagedModel.java
@@ -31,39 +31,41 @@ import com.fasterxml.jackson.annotation.JsonProperty;
* @author Oliver Gierke
* @author Greg Turnquist
*/
-public class PagedResources extends Resources {
+public class PagedModel extends CollectionModel {
- public static PagedResources> NO_PAGE = new PagedResources<>();
+ public static PagedModel> NO_PAGE = new PagedModel<>();
private PageMetadata metadata;
/**
* Default constructor to allow instantiation by reflection.
*/
- protected PagedResources() {
+ protected PagedModel() {
this(new ArrayList<>(), null);
}
/**
- * Creates a new {@link PagedResources} from the given content, {@link PageMetadata} and {@link Link}s (optional).
+ * Creates a new {@link PagedModel} from the given content, {@link PageMetadata} and {@link Link}s (optional).
*
* @param content must not be {@literal null}.
* @param metadata
* @param links
*/
- public PagedResources(Collection content, PageMetadata metadata, Link... links) {
+ public PagedModel(Collection content, PageMetadata metadata, Link... links) {
this(content, metadata, Arrays.asList(links));
}
/**
- * Creates a new {@link PagedResources} from the given content {@link PageMetadata} and {@link Link}s.
+ * Creates a new {@link PagedModel} from the given content {@link PageMetadata} and {@link Link}s.
*
* @param content must not be {@literal null}.
* @param metadata
* @param links
*/
- public PagedResources(Collection content, PageMetadata metadata, Iterable links) {
+ public PagedModel(Collection content, PageMetadata metadata, Iterable links) {
+
super(content, links);
+
this.metadata = metadata;
}
@@ -78,23 +80,23 @@ public class PagedResources extends Resources {
}
/**
- * Factory method to easily create a {@link PagedResources} instance from a set of entities and pagination metadata.
+ * Factory method to easily create a {@link PagedModel} instance from a set of entities and pagination metadata.
*
* @param content must not be {@literal null}.
* @param metadata
* @return
*/
@SuppressWarnings("unchecked")
- public static , S> PagedResources wrap(Iterable content, PageMetadata metadata) {
+ public static , S> PagedModel wrap(Iterable content, PageMetadata metadata) {
Assert.notNull(content, "Content must not be null!");
ArrayList resources = new ArrayList<>();
for (S element : content) {
- resources.add((T) new Resource<>(element));
+ resources.add((T) new EntityModel<>(element));
}
- return new PagedResources<>(resources, metadata);
+ return new PagedModel<>(resources, metadata);
}
/**
@@ -141,7 +143,7 @@ public class PagedResources extends Resources {
return false;
}
- PagedResources> that = (PagedResources>) obj;
+ PagedModel> that = (PagedModel>) obj;
boolean metadataEquals = this.metadata == null ? that.metadata == null : this.metadata.equals(that.metadata);
return metadataEquals && super.equals(obj);
diff --git a/src/main/java/org/springframework/hateoas/ResourceSupport.java b/src/main/java/org/springframework/hateoas/RepresentationModel.java
similarity index 60%
rename from src/main/java/org/springframework/hateoas/ResourceSupport.java
rename to src/main/java/org/springframework/hateoas/RepresentationModel.java
index 089061b8..ea9260b1 100755
--- a/src/main/java/org/springframework/hateoas/ResourceSupport.java
+++ b/src/main/java/org/springframework/hateoas/RepresentationModel.java
@@ -33,15 +33,15 @@ import com.fasterxml.jackson.annotation.JsonProperty;
* @author Johhny Lim
* @author Greg Turnquist
*/
-public class ResourceSupport implements Identifiable {
+public class RepresentationModel> implements Identifiable {
private final List links;
- public ResourceSupport() {
+ public RepresentationModel() {
this.links = new ArrayList<>();
}
- public ResourceSupport(Link initialLink) {
+ public RepresentationModel(Link initialLink) {
Assert.notNull(initialLink, "initialLink must not be null!");
@@ -49,7 +49,7 @@ public class ResourceSupport implements Identifiable {
this.links.add(initialLink);
}
- public ResourceSupport(List initialLinks) {
+ public RepresentationModel(List initialLinks) {
Assert.notNull(initialLinks, "initialLinks must not be null!");
@@ -70,11 +70,14 @@ public class ResourceSupport implements Identifiable {
*
* @param link
*/
- public void add(Link link) {
+ @SuppressWarnings("unchecked")
+ public T add(Link link) {
Assert.notNull(link, "Link must not be null!");
this.links.add(link);
+
+ return (T) this;
}
/**
@@ -82,11 +85,14 @@ public class ResourceSupport implements Identifiable {
*
* @param links
*/
- public void add(Iterable links) {
+ @SuppressWarnings("unchecked")
+ public T add(Iterable links) {
Assert.notNull(links, "Given links must not be null!");
links.forEach(this::add);
+
+ return (T) this;
}
/**
@@ -94,11 +100,14 @@ public class ResourceSupport implements Identifiable {
*
* @param links must not be {@literal null}.
*/
- public void add(Link... links) {
+ @SuppressWarnings("unchecked")
+ public T add(Link... links) {
Assert.notNull(links, "Given links must not be null!");
add(Arrays.asList(links));
+
+ return (T) this;
}
/**
@@ -137,58 +146,90 @@ public class ResourceSupport implements Identifiable {
/**
* Removes all {@link Link}s added to the resource so far.
*/
- public void removeLinks() {
+ @SuppressWarnings("unchecked")
+ public T removeLinks() {
+
this.links.clear();
+
+ return (T) this;
}
/**
- * Returns the link with the given rel.
+ * Returns the link with the given relation.
*
- * @param rel
- * @return the link with the given rel or {@link Optional#empty()} if none found.
+ * @param relation must not be {@literal null} or empty.
+ * @return the link with the given relation or {@link Optional#empty()} if none found.
*/
- public Optional getLink(String rel) {
- return getLink(LinkRelation.of(rel));
+ public Optional getLink(String relation) {
+ return getLink(LinkRelation.of(relation));
}
- public Optional getLink(LinkRelation rel) {
+ /**
+ * Returns the link with the given {@link LinkRelation}.
+ *
+ * @param relation
+ * @return
+ */
+ public Optional getLink(LinkRelation relation) {
return links.stream() //
- .filter(it -> it.hasRel(rel)) //
+ .filter(it -> it.hasRel(relation)) //
.findFirst();
}
/**
- * Returns the link with the given rel.
+ * Returns the link with the given relation.
*
- * @param rel
- * @return the link with the given rel.
- * @throws IllegalArgumentException in case no link with the given rel can be found.
+ * @param relation must not be {@literal null} or empty.
+ * @return the link with the given relation.
+ * @throws IllegalArgumentException in case no link with the given relation can be found.
*/
- public Link getRequiredLink(String rel) {
+ public Link getRequiredLink(String relation) {
- return getLink(rel) //
- .orElseThrow(() -> new IllegalArgumentException(String.format("No link with rel %s found!", rel)));
- }
-
- public Link getRequiredLink(LinkRelation rel) {
- return getRequiredLink(rel.value());
+ return getLink(relation) //
+ .orElseThrow(() -> new IllegalArgumentException(String.format("No link with rel %s found!", relation)));
}
/**
- * Returns all {@link Link}s with the given relation type.
+ * Returns the link with the given relation.
*
+ * @param relation must not be {@literal null}.
+ * @return the link with the given relation.
+ * @throws IllegalArgumentException in case no link with the given relation can be found.
+ */
+ public Link getRequiredLink(LinkRelation relation) {
+
+ Assert.notNull(relation, "Link relation must not be null!");
+
+ return getRequiredLink(relation.value());
+ }
+
+ /**
+ * Returns all {@link Link}s with the given relation.
+ *
+ * @param relation must not be {@literal null}.
* @return the links in a {@link List}
*/
- public List getLinks(String rel) {
+ public List getLinks(String relation) {
+
+ Assert.hasText(relation, "Link relation must not be null or empty!");
return links.stream() //
- .filter(link -> link.hasRel(rel)) //
+ .filter(link -> link.hasRel(relation)) //
.collect(Collectors.toList());
}
- public List getLinks(LinkRelation rel) {
- return getLinks(rel.value());
+ /**
+ * Returns all {@link Link}s with the given relation.
+ *
+ * @param relation must not be {@literal null}.
+ * @return the links in a {@link List}
+ */
+ public List getLinks(LinkRelation relation) {
+
+ Assert.notNull(relation, "Link relation must not be null!");
+
+ return getLinks(relation.value());
}
/*
@@ -205,6 +246,7 @@ public class ResourceSupport implements Identifiable {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
+ @SuppressWarnings("unchecked")
public boolean equals(Object obj) {
if (this == obj) {
@@ -215,9 +257,9 @@ public class ResourceSupport implements Identifiable {
return false;
}
- ResourceSupport that = (ResourceSupport) obj;
+ T that = (T) obj;
- return this.links.equals(that.links);
+ return getLinks().equals(that.getLinks());
}
/*
diff --git a/src/main/java/org/springframework/hateoas/config/WebMvcHateoasConfiguration.java b/src/main/java/org/springframework/hateoas/config/WebMvcHateoasConfiguration.java
index d932f9cf..ba12b9f2 100644
--- a/src/main/java/org/springframework/hateoas/config/WebMvcHateoasConfiguration.java
+++ b/src/main/java/org/springframework/hateoas/config/WebMvcHateoasConfiguration.java
@@ -26,7 +26,7 @@ import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.hateoas.ResourceSupport;
+import org.springframework.hateoas.RepresentationModel;
import org.springframework.hateoas.server.mvc.TypeConstrainedMappingJackson2HttpMessageConverter;
import org.springframework.hateoas.server.mvc.UriComponentsContributor;
import org.springframework.hateoas.server.mvc.WebMvcLinkBuilderFactory;
@@ -84,7 +84,7 @@ class WebMvcHateoasConfiguration {
this.hypermediaTypes.forEach(hypermedia -> {
- converters.add(0, new TypeConstrainedMappingJackson2HttpMessageConverter(ResourceSupport.class,
+ converters.add(0, new TypeConstrainedMappingJackson2HttpMessageConverter(RepresentationModel.class,
hypermedia.getMediaTypes(), hypermedia.configureObjectMapper(mapper.copy())));
});
}
diff --git a/src/main/java/org/springframework/hateoas/mediatype/JacksonHelper.java b/src/main/java/org/springframework/hateoas/mediatype/JacksonHelper.java
index 0f5ab512..8b7adaa2 100644
--- a/src/main/java/org/springframework/hateoas/mediatype/JacksonHelper.java
+++ b/src/main/java/org/springframework/hateoas/mediatype/JacksonHelper.java
@@ -15,8 +15,8 @@
*/
package org.springframework.hateoas.mediatype;
-import org.springframework.hateoas.Resource;
-import org.springframework.hateoas.Resources;
+import org.springframework.hateoas.EntityModel;
+import org.springframework.hateoas.CollectionModel;
import com.fasterxml.jackson.databind.JavaType;
@@ -49,8 +49,8 @@ public final class JacksonHelper {
public static boolean isResourcesOfResource(JavaType type) {
return
- Resources.class.isAssignableFrom(type.getRawClass())
+ CollectionModel.class.isAssignableFrom(type.getRawClass())
&&
- Resource.class.isAssignableFrom(type.containedType(0).getRawClass());
+ EntityModel.class.isAssignableFrom(type.containedType(0).getRawClass());
}
}
diff --git a/src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java b/src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java
index ba248a8f..7746dfd5 100644
--- a/src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java
+++ b/src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java
@@ -35,7 +35,7 @@ import reactor.core.publisher.Mono;
import org.springframework.beans.BeanUtils;
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.AnnotationUtils;
-import org.springframework.hateoas.Resource;
+import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.support.WebStack;
import org.springframework.util.ReflectionUtils;
@@ -56,8 +56,8 @@ public class PropertyUtils {
public static Map findProperties(Object object) {
- if (object.getClass().equals(Resource.class)) {
- return findProperties(((Resource>) object).getContent());
+ if (object.getClass().equals(EntityModel.class)) {
+ return findProperties(((EntityModel>) object).getContent());
}
return getPropertyDescriptors(object.getClass())
@@ -83,7 +83,7 @@ public class PropertyUtils {
}
}
- if (resolvableType.getRawClass().equals(Resource.class)) {
+ if (resolvableType.getRawClass().equals(EntityModel.class)) {
return findPropertyNames(resolvableType.resolveGeneric(0));
} else {
return findPropertyNames(resolvableType.getRawClass());
diff --git a/src/main/java/org/springframework/hateoas/mediatype/collectionjson/ResourcesMixin.java b/src/main/java/org/springframework/hateoas/mediatype/collectionjson/CollectionRepresentationModelMixin.java
similarity index 88%
rename from src/main/java/org/springframework/hateoas/mediatype/collectionjson/ResourcesMixin.java
rename to src/main/java/org/springframework/hateoas/mediatype/collectionjson/CollectionRepresentationModelMixin.java
index b25acc60..52925719 100644
--- a/src/main/java/org/springframework/hateoas/mediatype/collectionjson/ResourcesMixin.java
+++ b/src/main/java/org/springframework/hateoas/mediatype/collectionjson/CollectionRepresentationModelMixin.java
@@ -17,7 +17,7 @@ package org.springframework.hateoas.mediatype.collectionjson;
import static org.springframework.hateoas.mediatype.collectionjson.Jackson2CollectionJsonModule.*;
-import org.springframework.hateoas.Resources;
+import org.springframework.hateoas.CollectionModel;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -27,6 +27,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
* @author Greg Turnquist
*/
@JsonDeserialize(using = CollectionJsonResourcesDeserializer.class)
-abstract class ResourcesMixin extends Resources {
+abstract class CollectionRepresentationModelMixin extends CollectionModel {
}
diff --git a/src/main/java/org/springframework/hateoas/mediatype/collectionjson/ResourceMixin.java b/src/main/java/org/springframework/hateoas/mediatype/collectionjson/EntityRepresentationModelMixin.java
similarity index 89%
rename from src/main/java/org/springframework/hateoas/mediatype/collectionjson/ResourceMixin.java
rename to src/main/java/org/springframework/hateoas/mediatype/collectionjson/EntityRepresentationModelMixin.java
index 0cd83f9c..ea4746cc 100644
--- a/src/main/java/org/springframework/hateoas/mediatype/collectionjson/ResourceMixin.java
+++ b/src/main/java/org/springframework/hateoas/mediatype/collectionjson/EntityRepresentationModelMixin.java
@@ -17,7 +17,7 @@ package org.springframework.hateoas.mediatype.collectionjson;
import static org.springframework.hateoas.mediatype.collectionjson.Jackson2CollectionJsonModule.*;
-import org.springframework.hateoas.Resource;
+import org.springframework.hateoas.EntityModel;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -27,6 +27,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
* @author Greg Turnquist
*/
@JsonDeserialize(using = CollectionJsonResourceDeserializer.class)
-abstract class ResourceMixin extends Resource {
+abstract class EntityRepresentationModelMixin extends EntityModel {
}
diff --git a/src/main/java/org/springframework/hateoas/mediatype/collectionjson/Jackson2CollectionJsonModule.java b/src/main/java/org/springframework/hateoas/mediatype/collectionjson/Jackson2CollectionJsonModule.java
index 7da9f7af..1e14196b 100644
--- a/src/main/java/org/springframework/hateoas/mediatype/collectionjson/Jackson2CollectionJsonModule.java
+++ b/src/main/java/org/springframework/hateoas/mediatype/collectionjson/Jackson2CollectionJsonModule.java
@@ -26,17 +26,17 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import org.springframework.hateoas.Affordance;
+import org.springframework.hateoas.CollectionModel;
+import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.IanaLinkRelations;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.Links;
import org.springframework.hateoas.Links.MergeMode;
+import org.springframework.hateoas.MediaTypes;
+import org.springframework.hateoas.PagedModel;
+import org.springframework.hateoas.RepresentationModel;
import org.springframework.hateoas.mediatype.JacksonHelper;
import org.springframework.hateoas.mediatype.PropertyUtils;
-import org.springframework.hateoas.MediaTypes;
-import org.springframework.hateoas.PagedResources;
-import org.springframework.hateoas.Resource;
-import org.springframework.hateoas.ResourceSupport;
-import org.springframework.hateoas.Resources;
import org.springframework.http.HttpMethod;
import com.fasterxml.jackson.core.JsonGenerator;
@@ -59,8 +59,8 @@ import com.fasterxml.jackson.databind.ser.ContextualSerializer;
import com.fasterxml.jackson.databind.type.TypeFactory;
/**
- * Jackson 2 module implementation to render {@link Resources}, {@link Resource}, and {@link ResourceSupport} instances
- * in Collection+JSON compatible JSON.
+ * Jackson 2 module implementation to render {@link CollectionModel}, {@link EntityModel}, and
+ * {@link RepresentationModel} instances in Collection+JSON compatible JSON.
*
* @author Greg Turnquist
* @author Oliver Drotbohm
@@ -73,10 +73,10 @@ class Jackson2CollectionJsonModule extends SimpleModule {
super("collection-json-module", new Version(1, 0, 0, null, "org.springframework.hateoas", "spring-hateoas"));
- setMixInAnnotation(ResourceSupport.class, ResourceSupportMixin.class);
- setMixInAnnotation(Resource.class, ResourceMixin.class);
- setMixInAnnotation(Resources.class, ResourcesMixin.class);
- setMixInAnnotation(PagedResources.class, PagedResourcesMixin.class);
+ setMixInAnnotation(RepresentationModel.class, RepresentationModelMixin.class);
+ setMixInAnnotation(EntityModel.class, EntityRepresentationModelMixin.class);
+ setMixInAnnotation(CollectionModel.class, CollectionRepresentationModelMixin.class);
+ setMixInAnnotation(PagedModel.class, PagedResourcesMixin.class);
addSerializer(new CollectionJsonPagedResourcesSerializer());
addSerializer(new CollectionJsonResourcesSerializer());
@@ -160,7 +160,7 @@ class Jackson2CollectionJsonModule extends SimpleModule {
}
}
- static class CollectionJsonResourceSupportSerializer extends ContainerSerializer
+ static class CollectionJsonResourceSupportSerializer extends ContainerSerializer>
implements ContextualSerializer {
private static final long serialVersionUID = 6127711241993352699L;
@@ -173,12 +173,13 @@ class Jackson2CollectionJsonModule extends SimpleModule {
CollectionJsonResourceSupportSerializer(BeanProperty property) {
- super(ResourceSupport.class, false);
+ super(RepresentationModel.class, false);
this.property = property;
}
@Override
- public void serialize(ResourceSupport value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
+ public void serialize(RepresentationModel> value, JsonGenerator jgen, SerializerProvider provider)
+ throws IOException {
String href = value.getRequiredLink(IanaLinkRelations.SELF.value()).getHref();
@@ -220,7 +221,7 @@ class Jackson2CollectionJsonModule extends SimpleModule {
}
@Override
- public boolean hasSingleElement(ResourceSupport value) {
+ public boolean hasSingleElement(RepresentationModel> value) {
return true;
}
@@ -230,7 +231,7 @@ class Jackson2CollectionJsonModule extends SimpleModule {
}
}
- static class CollectionJsonResourceSerializer extends ContainerSerializer>
+ static class CollectionJsonResourceSerializer extends ContainerSerializer>
implements ContextualSerializer {
private static final long serialVersionUID = 2212535956767860364L;
@@ -243,12 +244,12 @@ class Jackson2CollectionJsonModule extends SimpleModule {
CollectionJsonResourceSerializer(BeanProperty property) {
- super(Resource.class, false);
+ super(EntityModel.class, false);
this.property = property;
}
@Override
- public void serialize(Resource> value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
+ public void serialize(EntityModel> value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
String href = value.getRequiredLink(IanaLinkRelations.SELF).getHref();
Links withoutSelfLink = value.getLinks().without(IanaLinkRelations.SELF);
@@ -287,7 +288,7 @@ class Jackson2CollectionJsonModule extends SimpleModule {
}
@Override
- public boolean hasSingleElement(Resource> value) {
+ public boolean hasSingleElement(EntityModel> value) {
return true;
}
@@ -297,12 +298,12 @@ class Jackson2CollectionJsonModule extends SimpleModule {
}
}
- static class CollectionJsonResourcesSerializer extends ContainerSerializer> {
+ static class CollectionJsonResourcesSerializer extends ContainerSerializer> {
private static final long serialVersionUID = -278986431091914402L;
CollectionJsonResourcesSerializer() {
- super(Resources.class, false);
+ super(CollectionModel.class, false);
}
/*
@@ -310,7 +311,8 @@ class Jackson2CollectionJsonModule extends SimpleModule {
* @see com.fasterxml.jackson.databind.ser.std.StdSerializer#serialize(java.lang.Object, com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.databind.SerializerProvider)
*/
@Override
- public void serialize(Resources> value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
+ public void serialize(CollectionModel> value, JsonGenerator jgen, SerializerProvider provider)
+ throws IOException {
CollectionJson