From 8cb01b103c8d7b92d55e9b76f4a6f68f809eda47 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 19 Nov 2024 15:34:10 +0100 Subject: [PATCH] Adopt to deprecation removals in Commons. Closes #2437 --- .../data/rest/core/UriToEntityConverter.java | 13 ++++------ ...ormationHandlerMethodArgumentResolver.java | 4 +-- .../AggregateReferenceResolvingModule.java | 3 +-- .../rest/webmvc/json/DomainObjectReader.java | 26 +++++++------------ .../data/rest/webmvc/json/JsonSchema.java | 5 ++-- .../json/PersistentEntityJackson2Module.java | 5 ++-- ...PersistentEntityToJsonSchemaConverter.java | 5 ++-- .../webmvc/json/patch/JsonPointerMapping.java | 3 +-- .../data/rest/webmvc/json/patch/SpelPath.java | 21 +++++++-------- .../PersistentEntityResourceProcessor.java | 3 +-- .../rest/webmvc/json/JsonSchemaUnitTests.java | 3 +-- 11 files changed, 36 insertions(+), 55 deletions(-) diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/UriToEntityConverter.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/UriToEntityConverter.java index 00eeed3d2..35118de67 100644 --- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/UriToEntityConverter.java +++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/UriToEntityConverter.java @@ -27,7 +27,7 @@ import org.springframework.core.convert.converter.GenericConverter; import org.springframework.data.mapping.context.PersistentEntities; import org.springframework.data.repository.support.Repositories; import org.springframework.data.repository.support.RepositoryInvokerFactory; -import org.springframework.data.util.ReflectionUtils; +import org.springframework.data.util.ClassUtils; import org.springframework.data.util.TypeInformation; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; @@ -41,8 +41,8 @@ import org.springframework.util.Assert; */ public class UriToEntityConverter implements GenericConverter { - private static final Class ASSOCIATION_TYPE = ReflectionUtils - .loadIfPresent("org.jmolecules.ddd.types.Association", UriToEntityConverter.class.getClassLoader()); + private static final Class ASSOCIATION_TYPE = ClassUtils.loadIfPresent("org.jmolecules.ddd.types.Association", + UriToEntityConverter.class.getClassLoader()); private final PersistentEntities entities; private final RepositoryInvokerFactory invokerFactory; @@ -120,15 +120,12 @@ public class UriToEntityConverter implements GenericConverter { if (entity.isEmpty()) { throw new ConversionFailedException(sourceType, targetType, source, - new IllegalArgumentException( - "No PersistentEntity information available for " + targetType.getType())); + new IllegalArgumentException("No PersistentEntity information available for " + targetType.getType())); } var segment = getIdentifierSegment(source, sourceType, targetType); - return invokerFactory.getInvokerFor(targetType.getType()) - .invokeFindById(segment) - .orElse(null); + return invokerFactory.getInvokerFor(targetType.getType()).invokeFindById(segment).orElse(null); } private static String getIdentifierSegment(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/QuerydslAwareRootResourceInformationHandlerMethodArgumentResolver.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/QuerydslAwareRootResourceInformationHandlerMethodArgumentResolver.java index 08e4d8429..b7c5fac07 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/QuerydslAwareRootResourceInformationHandlerMethodArgumentResolver.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/QuerydslAwareRootResourceInformationHandlerMethodArgumentResolver.java @@ -31,7 +31,7 @@ import org.springframework.data.repository.support.Repositories; import org.springframework.data.repository.support.RepositoryInvoker; import org.springframework.data.repository.support.RepositoryInvokerFactory; import org.springframework.data.rest.webmvc.RootResourceInformation; -import org.springframework.data.util.ClassTypeInformation; +import org.springframework.data.util.TypeInformation; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.method.support.HandlerMethodArgumentResolver; @@ -91,7 +91,7 @@ class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolver private Optional, Predicate>> getRepositoryAndPredicate( QuerydslPredicateExecutor repository, Class domainType, Map parameters) { - ClassTypeInformation type = ClassTypeInformation.from(domainType); + TypeInformation type = TypeInformation.of(domainType); QuerydslBindings bindings = factory.createBindingsFor(type); Predicate predicate = predicateBuilder.getPredicate(type, toMultiValueMap(parameters), bindings); diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/AggregateReferenceResolvingModule.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/AggregateReferenceResolvingModule.java index 8bb6e5e41..de908a3a0 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/AggregateReferenceResolvingModule.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/AggregateReferenceResolvingModule.java @@ -22,7 +22,6 @@ import org.springframework.data.rest.core.mapping.ResourceMappings; import org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module.AssociationUriResolvingDeserializerModifier.ValueInstantiatorCustomizer; import org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module.CollectionValueInstantiator; import org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module.UriStringDeserializer; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; import org.springframework.util.Assert; @@ -94,7 +93,7 @@ public class AggregateReferenceResolvingModule extends SimpleModule { return builder; } - TypeInformation type = ClassTypeInformation.from(description.getBeanClass()); + TypeInformation type = TypeInformation.of(description.getBeanClass()); ValueInstantiatorCustomizer customizer = new ValueInstantiatorCustomizer(builder.getValueInstantiator(), config); Iterator properties = builder.getProperties(); diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/DomainObjectReader.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/DomainObjectReader.java index f8ad97715..6bcc4ed31 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/DomainObjectReader.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/DomainObjectReader.java @@ -41,7 +41,6 @@ import org.springframework.data.mapping.context.PersistentEntities; import org.springframework.data.mapping.model.ConvertingPropertyAccessor; import org.springframework.data.rest.webmvc.mapping.Associations; import org.springframework.data.rest.webmvc.util.InputStreamHttpInputMessage; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.lang.Nullable; @@ -140,8 +139,7 @@ public class DomainObjectReader { boolean isTypeChange = !source.getClass().isInstance(target); - boolean immutableTarget = entities.getPersistentEntity(target.getClass()) - .map(PersistentEntity::isImmutable) + boolean immutableTarget = entities.getPersistentEntity(target.getClass()).map(PersistentEntity::isImmutable) .orElse(true); // Not a Spring Data managed type -> no detailed merging return entities.getPersistentEntity(isTypeChange ? source.getClass() : target.getClass()) // @@ -362,11 +360,8 @@ public class DomainObjectReader { Assert.notNull(mapper, "ObjectMapper must not be null"); // Empty collection? Primitive? Enum? No need to merge. - if (array.isEmpty() - || collection.isEmpty() - || ClassUtils.isPrimitiveOrWrapper(componentType.getType()) - || componentType.getType().isEnum() - || entities.getPersistentEntity(componentType.getType()).isEmpty()) { + if (array.isEmpty() || collection.isEmpty() || ClassUtils.isPrimitiveOrWrapper(componentType.getType()) + || componentType.getType().isEnum() || entities.getPersistentEntity(componentType.getType()).isEmpty()) { return false; } @@ -386,9 +381,8 @@ public class DomainObjectReader { nestedObjectFound = true; // Use pre-read values if available. Deserialize node otherwise. - collection.add(rawValues != null - ? rawValues.apply(current) - : mapper.treeToValue(jsonNode, componentType.getType())); + collection + .add(rawValues != null ? rawValues.apply(current) : mapper.treeToValue(jsonNode, componentType.getType())); continue; } @@ -597,7 +591,7 @@ public class DomainObjectReader { private static TypeInformation getTypeToMap(Object value, TypeInformation type) { if (type == null) { - return ClassTypeInformation.OBJECT; + return TypeInformation.OBJECT; } if (value == null) { @@ -605,11 +599,10 @@ public class DomainObjectReader { } if (Enum.class.isInstance(value)) { - return ClassTypeInformation.from(((Enum) value).getDeclaringClass()); + return TypeInformation.of(((Enum) value).getDeclaringClass()); } - return value.getClass().equals(type.getType()) ? type : ClassTypeInformation.from(value.getClass()); - + return value.getClass().equals(type.getType()) ? type : TypeInformation.of(value.getClass()); } /** @@ -709,8 +702,7 @@ public class DomainObjectReader { result = mergeCollections(property, sourceValue, targetValue, mapper); } else if (property.isEntity()) { - result = targetValue.isEmpty() - ? sourceValue + result = targetValue.isEmpty() ? sourceValue : targetValue.flatMap(t -> sourceValue.map(s -> mergeForPut(s, t, mapper))); } else { result = sourceValue; diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JsonSchema.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JsonSchema.java index 64975e936..0c3535bdb 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JsonSchema.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JsonSchema.java @@ -27,7 +27,6 @@ import java.util.Set; import java.util.regex.Pattern; import org.springframework.data.rest.core.config.JsonSchemaFormat; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -325,7 +324,7 @@ public class JsonSchema { */ public static class JsonSchemaProperty extends AbstractJsonSchemaProperty { - private static final TypeInformation STRING_TYPE_INFORMATION = ClassTypeInformation.from(String.class); + private static final TypeInformation STRING_TYPE_INFORMATION = TypeInformation.of(String.class); public String description; public String type; @@ -351,7 +350,7 @@ public class JsonSchema { public JsonSchemaProperty withType(Class type) { Assert.notNull(type, "Type must not be null"); - return with(ClassTypeInformation.from(type)); + return with(TypeInformation.of(type)); } /** diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityJackson2Module.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityJackson2Module.java index 30222c5c4..7f796e294 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityJackson2Module.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityJackson2Module.java @@ -37,13 +37,13 @@ import org.springframework.data.projection.TargetAware; import org.springframework.data.repository.support.RepositoryInvoker; import org.springframework.data.repository.support.RepositoryInvokerFactory; import org.springframework.data.rest.core.UriToEntityConverter; +import org.springframework.data.rest.core.mapping.ResourceMappings; import org.springframework.data.rest.core.mapping.ResourceMetadata; import org.springframework.data.rest.core.support.EntityLookup; import org.springframework.data.rest.webmvc.EmbeddedResourcesAssembler; import org.springframework.data.rest.webmvc.PersistentEntityResource; import org.springframework.data.rest.webmvc.mapping.Associations; import org.springframework.data.rest.webmvc.mapping.LinkCollector; -import org.springframework.data.util.CastUtils; import org.springframework.data.util.TypeInformation; import org.springframework.hateoas.EntityModel; import org.springframework.hateoas.Link; @@ -859,10 +859,11 @@ public class PersistentEntityJackson2Module extends SimpleModule { } } + @SuppressWarnings("unchecked") private Object getLookupKey(Object value) { return lookups.getPluginFor(value.getClass()) // - .> map(CastUtils::cast) + .map(it -> (EntityLookup) it) .orElseThrow(() -> new IllegalArgumentException("No EntityLookup found for " + value.getClass().getName())) .getResourceIdentifier(value); } diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverter.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverter.java index d18f0455c..7cdbd7a94 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverter.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverter.java @@ -49,7 +49,6 @@ import org.springframework.data.rest.webmvc.json.JsonSchema.EnumProperty; import org.springframework.data.rest.webmvc.json.JsonSchema.Item; import org.springframework.data.rest.webmvc.json.JsonSchema.JsonSchemaProperty; import org.springframework.data.rest.webmvc.mapping.Associations; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.Optionals; import org.springframework.data.util.TypeInformation; import org.springframework.hateoas.mediatype.MessageResolver; @@ -72,7 +71,7 @@ public class PersistentEntityToJsonSchemaConverter implements ConditionalGeneric private static final TypeDescriptor STRING_TYPE = TypeDescriptor.valueOf(String.class); private static final TypeDescriptor SCHEMA_TYPE = TypeDescriptor.valueOf(JsonSchema.class); - private static final TypeInformation STRING_TYPE_INFORMATION = ClassTypeInformation.from(String.class); + private static final TypeInformation STRING_TYPE_INFORMATION = TypeInformation.of(String.class); private final Set convertiblePairs = new HashSet(); private final Associations associations; @@ -424,7 +423,7 @@ public class PersistentEntityToJsonSchemaConverter implements ConditionalGeneric @SuppressWarnings("rawtypes") public TypeInformation getPropertyType() { return property.map(it -> (TypeInformation) it.getTypeInformation()) - .orElseGet(() -> ClassTypeInformation.from(definition.getPrimaryMember().getRawType())); + .orElseGet(() -> TypeInformation.of(definition.getPrimaryMember().getRawType())); } public JsonSchemaProperty getSchemaProperty(ResourceDescription description, InternalMessageResolver resolver) { diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/JsonPointerMapping.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/JsonPointerMapping.java index 712e55567..e9a183c33 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/JsonPointerMapping.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/JsonPointerMapping.java @@ -20,7 +20,6 @@ import java.util.function.BiFunction; import org.springframework.data.mapping.PropertyPath; import org.springframework.data.mapping.PropertyReferenceException; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; import org.springframework.util.StringUtils; @@ -76,7 +75,7 @@ class JsonPointerMapping { PropertyPath base = null; StringBuilder result = new StringBuilder(); - TypeInformation currentType = ClassTypeInformation.from(type); + TypeInformation currentType = TypeInformation.of(type); for (int i = 0; i < strings.length; i++) { diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java index c3331c454..e40045368 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java @@ -27,7 +27,6 @@ import org.springframework.core.CollectionFactory; import org.springframework.core.convert.TypeDescriptor; import org.springframework.data.mapping.PropertyPath; import org.springframework.data.mapping.PropertyReferenceException; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; import org.springframework.expression.EvaluationContext; import org.springframework.expression.Expression; @@ -126,11 +125,10 @@ class SpelPath { Assert.notNull(path, "Path must not be null"); Assert.notNull(type, "Type must not be null"); - return READ_PATHS.computeIfAbsent(CacheKey.of(type, this, context), - key -> { - String mapped = new JsonPointerMapping(context).forRead(key.path.path, type); - return new TypedSpelPath(mapped, key.type, context.getEvaluationContext()); - }); + return READ_PATHS.computeIfAbsent(CacheKey.of(type, this, context), key -> { + String mapped = new JsonPointerMapping(context).forRead(key.path.path, type); + return new TypedSpelPath(mapped, key.type, context.getEvaluationContext()); + }); } /** @@ -144,11 +142,10 @@ class SpelPath { Assert.notNull(path, "Path must not be null"); Assert.notNull(type, "Type must not be null"); - return WRITE_PATHS.computeIfAbsent(CacheKey.of(type, this, context), - key -> { - String mapped = new JsonPointerMapping(context).forWrite(key.path.path, type); - return new TypedSpelPath(mapped, key.type, context.getEvaluationContext()); - }); + return WRITE_PATHS.computeIfAbsent(CacheKey.of(type, this, context), key -> { + String mapped = new JsonPointerMapping(context).forWrite(key.path.path, type); + return new TypedSpelPath(mapped, key.type, context.getEvaluationContext()); + }); } private static final class CacheKey { @@ -585,7 +582,7 @@ class SpelPath { private static final class SpelExpressionBuilder { - private static final TypeInformation STRING_TYPE = ClassTypeInformation.from(String.class); + private static final TypeInformation STRING_TYPE = TypeInformation.of(String.class); private final @Nullable PropertyPath basePath; private final Class type; diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/PersistentEntityResourceProcessor.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/PersistentEntityResourceProcessor.java index ea13f601a..5203d2ba3 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/PersistentEntityResourceProcessor.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/PersistentEntityResourceProcessor.java @@ -8,7 +8,6 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.repository.support.Repositories; import org.springframework.data.rest.webmvc.PersistentEntityResource; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; import org.springframework.hateoas.EntityModel; import org.springframework.hateoas.server.RepresentationModelProcessor; @@ -25,7 +24,7 @@ public class PersistentEntityResourceProcessor implements RepresentationModelPro List>> resourceProcessors) { if (null != resourceProcessors) { for (RepresentationModelProcessor> rp : resourceProcessors) { - TypeInformation typeInfo = ClassTypeInformation.from(rp.getClass()); + TypeInformation typeInfo = TypeInformation.of(rp.getClass()); TypeInformation domainType = typeInfo.getTypeArguments().get(0); if (null != repositories.getPersistentEntity(domainType.getType())) { this.resourceProcessors.add(new DomainTypeResourceProcessor(domainType.getType(), rp)); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JsonSchemaUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JsonSchemaUnitTests.java index 01f6310ed..61e83fcaf 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JsonSchemaUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JsonSchemaUnitTests.java @@ -19,7 +19,6 @@ import static org.assertj.core.api.Assertions.*; import org.junit.jupiter.api.Test; import org.springframework.data.rest.webmvc.json.JsonSchema.JsonSchemaProperty; -import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; /** @@ -29,7 +28,7 @@ import org.springframework.data.util.TypeInformation; */ class JsonSchemaUnitTests { - static final TypeInformation type = ClassTypeInformation.from(Sample.class); + static final TypeInformation type = TypeInformation.of(Sample.class); @Test // DATAREST-492 void considersNumberPrimitivesJsonSchemaNumbers() {