Adopt to deprecation removals in Commons.

Closes #2437
This commit is contained in:
Mark Paluch
2024-11-19 15:34:10 +01:00
parent ce95089354
commit 8cb01b103c
11 changed files with 36 additions and 55 deletions

View File

@@ -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) {

View File

@@ -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<Pair<QuerydslPredicateExecutor<?>, Predicate>> getRepositoryAndPredicate(
QuerydslPredicateExecutor<?> repository, Class<?> domainType, Map<String, String[]> parameters) {
ClassTypeInformation<?> type = ClassTypeInformation.from(domainType);
TypeInformation<?> type = TypeInformation.of(domainType);
QuerydslBindings bindings = factory.createBindingsFor(type);
Predicate predicate = predicateBuilder.getPredicate(type, toMultiValueMap(parameters), bindings);

View File

@@ -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<SettableBeanProperty> properties = builder.getProperties();

View File

@@ -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;

View File

@@ -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<JsonSchemaProperty> {
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));
}
/**

View File

@@ -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()) //
.<EntityLookup<Object>> map(CastUtils::cast)
.map(it -> (EntityLookup<Object>) it)
.orElseThrow(() -> new IllegalArgumentException("No EntityLookup found for " + value.getClass().getName()))
.getResourceIdentifier(value);
}

View File

@@ -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<ConvertiblePair> convertiblePairs = new HashSet<ConvertiblePair>();
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) {

View File

@@ -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++) {

View File

@@ -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> STRING_TYPE = ClassTypeInformation.from(String.class);
private static final TypeInformation<String> STRING_TYPE = TypeInformation.of(String.class);
private final @Nullable PropertyPath basePath;
private final Class<?> type;

View File

@@ -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<RepresentationModelProcessor<EntityModel<?>>> resourceProcessors) {
if (null != resourceProcessors) {
for (RepresentationModelProcessor<EntityModel<?>> 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));

View File

@@ -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() {