From fd132c9a2f9f394e0627df01625d8b0f3b7005b4 Mon Sep 17 00:00:00 2001 From: Patrick ALLAIN Date: Wed, 3 Jun 2020 09:01:49 +0200 Subject: [PATCH] [#1300] Fix several test switching generics order --- .../springframework/hateoas/AbstractCollectionModel.java | 6 ++---- .../java/org/springframework/hateoas/CollectionModel.java | 7 +------ src/main/java/org/springframework/hateoas/PagedModel.java | 2 +- .../collectionjson/Jackson2CollectionJsonModule.java | 2 +- .../hateoas/mediatype/hal/forms/HalFormsSerializers.java | 6 +++--- .../springframework/hateoas/mediatype/uber/UberData.java | 2 +- .../server/mvc/RepresentationModelProcessorInvoker.java | 4 ++-- .../mediatype/uber/Jackson2UberIntegrationTest.java | 4 ++-- 8 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/springframework/hateoas/AbstractCollectionModel.java b/src/main/java/org/springframework/hateoas/AbstractCollectionModel.java index 557150994..df6f9076c 100644 --- a/src/main/java/org/springframework/hateoas/AbstractCollectionModel.java +++ b/src/main/java/org/springframework/hateoas/AbstractCollectionModel.java @@ -20,12 +20,10 @@ import org.springframework.util.Assert; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.Objects; -import java.util.function.Supplier; /** * General helper to easily create a wrapper for a collection of entities. @@ -33,7 +31,7 @@ * @author Oliver Gierke * @author Greg Turnquist */ -public class AbstractCollectionModel, T> extends RepresentationModel implements Iterable { +public class AbstractCollectionModel> extends RepresentationModel implements Iterable { private final Collection content; @@ -98,7 +96,7 @@ public boolean equals(@Nullable Object obj) { return false; } - AbstractCollectionModel that = (AbstractCollectionModel) obj; + AbstractCollectionModel that = (AbstractCollectionModel) obj; return Objects.equals(this.content, that.content); } diff --git a/src/main/java/org/springframework/hateoas/CollectionModel.java b/src/main/java/org/springframework/hateoas/CollectionModel.java index ef0daf5cb..05abff569 100644 --- a/src/main/java/org/springframework/hateoas/CollectionModel.java +++ b/src/main/java/org/springframework/hateoas/CollectionModel.java @@ -17,22 +17,17 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; -import java.util.Iterator; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; -import com.fasterxml.jackson.annotation.JsonProperty; - /** * General helper to easily create a wrapper for a collection of entities. * * @author Oliver Gierke * @author Greg Turnquist */ -public class CollectionModel extends AbstractCollectionModel, T> implements Iterable { +public class CollectionModel extends AbstractCollectionModel> implements Iterable { /** * Creates an empty {@link CollectionModel} instance. diff --git a/src/main/java/org/springframework/hateoas/PagedModel.java b/src/main/java/org/springframework/hateoas/PagedModel.java index 4736b53f1..88c6a1d0a 100644 --- a/src/main/java/org/springframework/hateoas/PagedModel.java +++ b/src/main/java/org/springframework/hateoas/PagedModel.java @@ -34,7 +34,7 @@ * @author Oliver Gierke * @author Greg Turnquist */ -public class PagedModel extends AbstractCollectionModel, T> { +public class PagedModel extends AbstractCollectionModel> { public static PagedModel NO_PAGE = new PagedModel<>(); 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 aa41a3d89..c4097418a 100644 --- a/src/main/java/org/springframework/hateoas/mediatype/collectionjson/Jackson2CollectionJsonModule.java +++ b/src/main/java/org/springframework/hateoas/mediatype/collectionjson/Jackson2CollectionJsonModule.java @@ -915,7 +915,7 @@ private CollectionJsonPagedResourcesDeserializer(JavaType contentType) { } } - private static List> resourcesToCollectionJsonItems(AbstractCollectionModel resources) { + private static List> resourcesToCollectionJsonItems(AbstractCollectionModel resources) { return resources.getContent().stream().map(content -> { diff --git a/src/main/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsSerializers.java b/src/main/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsSerializers.java index d5e309a36..aa72e9911 100644 --- a/src/main/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsSerializers.java +++ b/src/main/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsSerializers.java @@ -210,7 +210,7 @@ public JsonSerializer createContextual(SerializerProvider prov, BeanProperty /** * Serializer for {@link CollectionModel} */ - static class HalFormsCollectionModelSerializer extends ContainerSerializer> + static class HalFormsCollectionModelSerializer extends ContainerSerializer> implements ContextualSerializer { private static final long serialVersionUID = -3601146866067500734L; @@ -243,7 +243,7 @@ static class HalFormsCollectionModelSerializer extends ContainerSerializer value, JsonGenerator gen, SerializerProvider provider) throws IOException { + public void serialize(AbstractCollectionModel value, JsonGenerator gen, SerializerProvider provider) throws IOException { EmbeddedMapper mapper = configuration.isApplyPropertyNamingStrategy() // ? embeddedMapper.with(provider.getConfig().getPropertyNamingStrategy()) // @@ -298,7 +298,7 @@ public JsonSerializer getContentSerializer() { */ @Override @SuppressWarnings("null") - public boolean hasSingleElement(AbstractCollectionModel resources) { + public boolean hasSingleElement(AbstractCollectionModel resources) { return resources.getContent().size() == 1; } diff --git a/src/main/java/org/springframework/hateoas/mediatype/uber/UberData.java b/src/main/java/org/springframework/hateoas/mediatype/uber/UberData.java index 61e290091..9a02ba365 100644 --- a/src/main/java/org/springframework/hateoas/mediatype/uber/UberData.java +++ b/src/main/java/org/springframework/hateoas/mediatype/uber/UberData.java @@ -204,7 +204,7 @@ static List extractLinksAndContent(EntityModel resource) { * @param resources * @return */ - private static List extractLinksAndCollectionContent(AbstractCollectionModel resources) { + private static List extractLinksAndCollectionContent(AbstractCollectionModel resources) { List data = extractLinks(resources); diff --git a/src/main/java/org/springframework/hateoas/server/mvc/RepresentationModelProcessorInvoker.java b/src/main/java/org/springframework/hateoas/server/mvc/RepresentationModelProcessorInvoker.java index 947ffdfdd..f410a4e8d 100644 --- a/src/main/java/org/springframework/hateoas/server/mvc/RepresentationModelProcessorInvoker.java +++ b/src/main/java/org/springframework/hateoas/server/mvc/RepresentationModelProcessorInvoker.java @@ -385,7 +385,7 @@ public boolean supports(ResolvableType type, Object value) { * @return */ - static boolean isValueTypeMatch(@Nullable AbstractCollectionModel collectionModel, ResolvableType target) { + static boolean isValueTypeMatch(@Nullable AbstractCollectionModel collectionModel, ResolvableType target) { if (collectionModel == null) { return false; @@ -413,7 +413,7 @@ static boolean isValueTypeMatch(@Nullable AbstractCollectionModel collectio } Object element = content.iterator().next(); - ResolvableType resourceType = superType.getGeneric(1); + ResolvableType resourceType = superType.getGeneric(0); if (element instanceof EntityModel) { return EntityModelProcessorWrapper.isValueTypeMatch((EntityModel) element, resourceType); diff --git a/src/test/java/org/springframework/hateoas/mediatype/uber/Jackson2UberIntegrationTest.java b/src/test/java/org/springframework/hateoas/mediatype/uber/Jackson2UberIntegrationTest.java index e4ba6e4e3..07a5f51e9 100644 --- a/src/test/java/org/springframework/hateoas/mediatype/uber/Jackson2UberIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/mediatype/uber/Jackson2UberIntegrationTest.java @@ -538,13 +538,13 @@ void handleTemplatedLinksOnDeserialization() throws IOException { assertThat(deserialized).isEqualTo(original); } - private static AbstractCollectionModel> setupAnnotatedPagedResources() { + private static AbstractCollectionModel, ?> setupAnnotatedPagedResources() { return setupAnnotatedPagedResources(2, 4); } @NotNull - private static AbstractCollectionModel> setupAnnotatedPagedResources(int size, int totalElements) { + private static AbstractCollectionModel, ?> setupAnnotatedPagedResources(int size, int totalElements) { List> content = new ArrayList<>(); Employee employee = new Employee("Frodo", "ring bearer");