Skip to content

Commit 6595fa3

Browse files
mp911deodrotbohm
authored andcommitted
Adopt to deprecation removals in Commons.
Closes #2437
1 parent 3d1566c commit 6595fa3

File tree

11 files changed

+36
-55
lines changed

11 files changed

+36
-55
lines changed

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/UriToEntityConverter.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.springframework.data.mapping.context.PersistentEntities;
2828
import org.springframework.data.repository.support.Repositories;
2929
import org.springframework.data.repository.support.RepositoryInvokerFactory;
30-
import org.springframework.data.util.ReflectionUtils;
30+
import org.springframework.data.util.ClassUtils;
3131
import org.springframework.data.util.TypeInformation;
3232
import org.springframework.lang.NonNull;
3333
import org.springframework.lang.Nullable;
@@ -41,8 +41,8 @@
4141
*/
4242
public class UriToEntityConverter implements GenericConverter {
4343

44-
private static final Class<?> ASSOCIATION_TYPE = ReflectionUtils
45-
.loadIfPresent("org.jmolecules.ddd.types.Association", UriToEntityConverter.class.getClassLoader());
44+
private static final Class<?> ASSOCIATION_TYPE = ClassUtils.loadIfPresent("org.jmolecules.ddd.types.Association",
45+
UriToEntityConverter.class.getClassLoader());
4646

4747
private final PersistentEntities entities;
4848
private final RepositoryInvokerFactory invokerFactory;
@@ -120,15 +120,12 @@ public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDe
120120

121121
if (entity.isEmpty()) {
122122
throw new ConversionFailedException(sourceType, targetType, source,
123-
new IllegalArgumentException(
124-
"No PersistentEntity information available for " + targetType.getType()));
123+
new IllegalArgumentException("No PersistentEntity information available for " + targetType.getType()));
125124
}
126125

127126
var segment = getIdentifierSegment(source, sourceType, targetType);
128127

129-
return invokerFactory.getInvokerFor(targetType.getType())
130-
.invokeFindById(segment)
131-
.orElse(null);
128+
return invokerFactory.getInvokerFor(targetType.getType()).invokeFindById(segment).orElse(null);
132129
}
133130

134131
private static String getIdentifierSegment(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/QuerydslAwareRootResourceInformationHandlerMethodArgumentResolver.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.springframework.data.repository.support.RepositoryInvoker;
3232
import org.springframework.data.repository.support.RepositoryInvokerFactory;
3333
import org.springframework.data.rest.webmvc.RootResourceInformation;
34-
import org.springframework.data.util.ClassTypeInformation;
34+
import org.springframework.data.util.TypeInformation;
3535
import org.springframework.util.LinkedMultiValueMap;
3636
import org.springframework.util.MultiValueMap;
3737
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
@@ -91,7 +91,7 @@ protected RepositoryInvoker postProcess(MethodParameter parameter, RepositoryInv
9191
private Optional<Pair<QuerydslPredicateExecutor<?>, Predicate>> getRepositoryAndPredicate(
9292
QuerydslPredicateExecutor<?> repository, Class<?> domainType, Map<String, String[]> parameters) {
9393

94-
ClassTypeInformation<?> type = ClassTypeInformation.from(domainType);
94+
TypeInformation<?> type = TypeInformation.of(domainType);
9595

9696
QuerydslBindings bindings = factory.createBindingsFor(type);
9797
Predicate predicate = predicateBuilder.getPredicate(type, toMultiValueMap(parameters), bindings);

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/AggregateReferenceResolvingModule.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module.AssociationUriResolvingDeserializerModifier.ValueInstantiatorCustomizer;
2323
import org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module.CollectionValueInstantiator;
2424
import org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module.UriStringDeserializer;
25-
import org.springframework.data.util.ClassTypeInformation;
2625
import org.springframework.data.util.TypeInformation;
2726
import org.springframework.util.Assert;
2827

@@ -94,7 +93,7 @@ public BeanDeserializerBuilder updateBuilder(DeserializationConfig config, BeanD
9493
return builder;
9594
}
9695

97-
TypeInformation<?> type = ClassTypeInformation.from(description.getBeanClass());
96+
TypeInformation<?> type = TypeInformation.of(description.getBeanClass());
9897
ValueInstantiatorCustomizer customizer = new ValueInstantiatorCustomizer(builder.getValueInstantiator(), config);
9998
Iterator<SettableBeanProperty> properties = builder.getProperties();
10099

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/DomainObjectReader.java

+9-17
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
4242
import org.springframework.data.rest.webmvc.mapping.Associations;
4343
import org.springframework.data.rest.webmvc.util.InputStreamHttpInputMessage;
44-
import org.springframework.data.util.ClassTypeInformation;
4544
import org.springframework.data.util.TypeInformation;
4645
import org.springframework.http.converter.HttpMessageNotReadableException;
4746
import org.springframework.lang.Nullable;
@@ -140,8 +139,7 @@ <T> T mergeForPut(T source, T target, final ObjectMapper mapper) {
140139

141140
boolean isTypeChange = !source.getClass().isInstance(target);
142141

143-
boolean immutableTarget = entities.getPersistentEntity(target.getClass())
144-
.map(PersistentEntity::isImmutable)
142+
boolean immutableTarget = entities.getPersistentEntity(target.getClass()).map(PersistentEntity::isImmutable)
145143
.orElse(true); // Not a Spring Data managed type -> no detailed merging
146144

147145
return entities.getPersistentEntity(isTypeChange ? source.getClass() : target.getClass()) //
@@ -362,11 +360,8 @@ private boolean handleArrayNode(ArrayNode array, Collection<Object> collection,
362360
Assert.notNull(mapper, "ObjectMapper must not be null");
363361

364362
// Empty collection? Primitive? Enum? No need to merge.
365-
if (array.isEmpty()
366-
|| collection.isEmpty()
367-
|| ClassUtils.isPrimitiveOrWrapper(componentType.getType())
368-
|| componentType.getType().isEnum()
369-
|| entities.getPersistentEntity(componentType.getType()).isEmpty()) {
363+
if (array.isEmpty() || collection.isEmpty() || ClassUtils.isPrimitiveOrWrapper(componentType.getType())
364+
|| componentType.getType().isEnum() || entities.getPersistentEntity(componentType.getType()).isEmpty()) {
370365
return false;
371366
}
372367

@@ -386,9 +381,8 @@ private boolean handleArrayNode(ArrayNode array, Collection<Object> collection,
386381
nestedObjectFound = true;
387382

388383
// Use pre-read values if available. Deserialize node otherwise.
389-
collection.add(rawValues != null
390-
? rawValues.apply(current)
391-
: mapper.treeToValue(jsonNode, componentType.getType()));
384+
collection
385+
.add(rawValues != null ? rawValues.apply(current) : mapper.treeToValue(jsonNode, componentType.getType()));
392386

393387
continue;
394388
}
@@ -597,19 +591,18 @@ private static Class<?> typeOrObject(TypeInformation<?> type) {
597591
private static TypeInformation<?> getTypeToMap(Object value, TypeInformation<?> type) {
598592

599593
if (type == null) {
600-
return ClassTypeInformation.OBJECT;
594+
return TypeInformation.OBJECT;
601595
}
602596

603597
if (value == null) {
604598
return type;
605599
}
606600

607601
if (Enum.class.isInstance(value)) {
608-
return ClassTypeInformation.from(((Enum<?>) value).getDeclaringClass());
602+
return TypeInformation.of(((Enum<?>) value).getDeclaringClass());
609603
}
610604

611-
return value.getClass().equals(type.getType()) ? type : ClassTypeInformation.from(value.getClass());
612-
605+
return value.getClass().equals(type.getType()) ? type : TypeInformation.of(value.getClass());
613606
}
614607

615608
/**
@@ -709,8 +702,7 @@ public void doWithPersistentProperty(PersistentProperty<?> property) {
709702
result = mergeCollections(property, sourceValue, targetValue, mapper);
710703
} else if (property.isEntity()) {
711704

712-
result = targetValue.isEmpty()
713-
? sourceValue
705+
result = targetValue.isEmpty() ? sourceValue
714706
: targetValue.flatMap(t -> sourceValue.map(s -> mergeForPut(s, t, mapper)));
715707
} else {
716708
result = sourceValue;

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JsonSchema.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.regex.Pattern;
2828

2929
import org.springframework.data.rest.core.config.JsonSchemaFormat;
30-
import org.springframework.data.util.ClassTypeInformation;
3130
import org.springframework.data.util.TypeInformation;
3231
import org.springframework.util.Assert;
3332
import org.springframework.util.ClassUtils;
@@ -325,7 +324,7 @@ protected T withReadOnly() {
325324
*/
326325
public static class JsonSchemaProperty extends AbstractJsonSchemaProperty<JsonSchemaProperty> {
327326

328-
private static final TypeInformation<?> STRING_TYPE_INFORMATION = ClassTypeInformation.from(String.class);
327+
private static final TypeInformation<?> STRING_TYPE_INFORMATION = TypeInformation.of(String.class);
329328

330329
public String description;
331330
public String type;
@@ -351,7 +350,7 @@ public static class JsonSchemaProperty extends AbstractJsonSchemaProperty<JsonSc
351350
public JsonSchemaProperty withType(Class<?> type) {
352351

353352
Assert.notNull(type, "Type must not be null");
354-
return with(ClassTypeInformation.from(type));
353+
return with(TypeInformation.of(type));
355354
}
356355

357356
/**

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityJackson2Module.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
import org.springframework.data.repository.support.RepositoryInvoker;
3838
import org.springframework.data.repository.support.RepositoryInvokerFactory;
3939
import org.springframework.data.rest.core.UriToEntityConverter;
40+
import org.springframework.data.rest.core.mapping.ResourceMappings;
4041
import org.springframework.data.rest.core.mapping.ResourceMetadata;
4142
import org.springframework.data.rest.core.support.EntityLookup;
4243
import org.springframework.data.rest.webmvc.EmbeddedResourcesAssembler;
4344
import org.springframework.data.rest.webmvc.PersistentEntityResource;
4445
import org.springframework.data.rest.webmvc.mapping.Associations;
4546
import org.springframework.data.rest.webmvc.mapping.LinkCollector;
46-
import org.springframework.data.util.CastUtils;
4747
import org.springframework.data.util.TypeInformation;
4848
import org.springframework.hateoas.EntityModel;
4949
import org.springframework.hateoas.Link;
@@ -859,10 +859,11 @@ public void serialize(Object value, JsonGenerator gen, SerializerProvider provid
859859
}
860860
}
861861

862+
@SuppressWarnings("unchecked")
862863
private Object getLookupKey(Object value) {
863864

864865
return lookups.getPluginFor(value.getClass()) //
865-
.<EntityLookup<Object>> map(CastUtils::cast)
866+
.map(it -> (EntityLookup<Object>) it)
866867
.orElseThrow(() -> new IllegalArgumentException("No EntityLookup found for " + value.getClass().getName()))
867868
.getResourceIdentifier(value);
868869
}

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverter.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import org.springframework.data.rest.webmvc.json.JsonSchema.Item;
5050
import org.springframework.data.rest.webmvc.json.JsonSchema.JsonSchemaProperty;
5151
import org.springframework.data.rest.webmvc.mapping.Associations;
52-
import org.springframework.data.util.ClassTypeInformation;
5352
import org.springframework.data.util.Optionals;
5453
import org.springframework.data.util.TypeInformation;
5554
import org.springframework.hateoas.mediatype.MessageResolver;
@@ -72,7 +71,7 @@ public class PersistentEntityToJsonSchemaConverter implements ConditionalGeneric
7271

7372
private static final TypeDescriptor STRING_TYPE = TypeDescriptor.valueOf(String.class);
7473
private static final TypeDescriptor SCHEMA_TYPE = TypeDescriptor.valueOf(JsonSchema.class);
75-
private static final TypeInformation<?> STRING_TYPE_INFORMATION = ClassTypeInformation.from(String.class);
74+
private static final TypeInformation<?> STRING_TYPE_INFORMATION = TypeInformation.of(String.class);
7675

7776
private final Set<ConvertiblePair> convertiblePairs = new HashSet<ConvertiblePair>();
7877
private final Associations associations;
@@ -424,7 +423,7 @@ public JacksonProperty(JacksonMetadata metadata, Optional<? extends PersistentPr
424423
@SuppressWarnings("rawtypes")
425424
public TypeInformation<?> getPropertyType() {
426425
return property.map(it -> (TypeInformation) it.getTypeInformation())
427-
.orElseGet(() -> ClassTypeInformation.from(definition.getPrimaryMember().getRawType()));
426+
.orElseGet(() -> TypeInformation.of(definition.getPrimaryMember().getRawType()));
428427
}
429428

430429
public JsonSchemaProperty getSchemaProperty(ResourceDescription description, InternalMessageResolver resolver) {

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/JsonPointerMapping.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import org.springframework.data.mapping.PropertyPath;
2222
import org.springframework.data.mapping.PropertyReferenceException;
23-
import org.springframework.data.util.ClassTypeInformation;
2423
import org.springframework.data.util.TypeInformation;
2524
import org.springframework.util.StringUtils;
2625

@@ -76,7 +75,7 @@ private String verify(String pointer, Class<?> type, BiFunction<String, Class<?>
7675

7776
PropertyPath base = null;
7877
StringBuilder result = new StringBuilder();
79-
TypeInformation<?> currentType = ClassTypeInformation.from(type);
78+
TypeInformation<?> currentType = TypeInformation.of(type);
8079

8180
for (int i = 0; i < strings.length; i++) {
8281

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java

+9-12
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.springframework.core.convert.TypeDescriptor;
2828
import org.springframework.data.mapping.PropertyPath;
2929
import org.springframework.data.mapping.PropertyReferenceException;
30-
import org.springframework.data.util.ClassTypeInformation;
3130
import org.springframework.data.util.TypeInformation;
3231
import org.springframework.expression.EvaluationContext;
3332
import org.springframework.expression.Expression;
@@ -126,11 +125,10 @@ public ReadingOperations bindForRead(Class<?> type, BindContext context) {
126125
Assert.notNull(path, "Path must not be null");
127126
Assert.notNull(type, "Type must not be null");
128127

129-
return READ_PATHS.computeIfAbsent(CacheKey.of(type, this, context),
130-
key -> {
131-
String mapped = new JsonPointerMapping(context).forRead(key.path.path, type);
132-
return new TypedSpelPath(mapped, key.type, context.getEvaluationContext());
133-
});
128+
return READ_PATHS.computeIfAbsent(CacheKey.of(type, this, context), key -> {
129+
String mapped = new JsonPointerMapping(context).forRead(key.path.path, type);
130+
return new TypedSpelPath(mapped, key.type, context.getEvaluationContext());
131+
});
134132
}
135133

136134
/**
@@ -144,11 +142,10 @@ public WritingOperations bindForWrite(Class<?> type, BindContext context) {
144142
Assert.notNull(path, "Path must not be null");
145143
Assert.notNull(type, "Type must not be null");
146144

147-
return WRITE_PATHS.computeIfAbsent(CacheKey.of(type, this, context),
148-
key -> {
149-
String mapped = new JsonPointerMapping(context).forWrite(key.path.path, type);
150-
return new TypedSpelPath(mapped, key.type, context.getEvaluationContext());
151-
});
145+
return WRITE_PATHS.computeIfAbsent(CacheKey.of(type, this, context), key -> {
146+
String mapped = new JsonPointerMapping(context).forWrite(key.path.path, type);
147+
return new TypedSpelPath(mapped, key.type, context.getEvaluationContext());
148+
});
152149
}
153150

154151
private static final class CacheKey {
@@ -585,7 +582,7 @@ private static SkippedPropertyPath createOrSkip(Optional<SkippedPropertyPath> cu
585582

586583
private static final class SpelExpressionBuilder {
587584

588-
private static final TypeInformation<String> STRING_TYPE = ClassTypeInformation.from(String.class);
585+
private static final TypeInformation<String> STRING_TYPE = TypeInformation.of(String.class);
589586

590587
private final @Nullable PropertyPath basePath;
591588
private final Class<?> type;

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/PersistentEntityResourceProcessor.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.springframework.beans.factory.annotation.Autowired;
99
import org.springframework.data.repository.support.Repositories;
1010
import org.springframework.data.rest.webmvc.PersistentEntityResource;
11-
import org.springframework.data.util.ClassTypeInformation;
1211
import org.springframework.data.util.TypeInformation;
1312
import org.springframework.hateoas.EntityModel;
1413
import org.springframework.hateoas.server.RepresentationModelProcessor;
@@ -25,7 +24,7 @@ public PersistentEntityResourceProcessor(Repositories repositories,
2524
List<RepresentationModelProcessor<EntityModel<?>>> resourceProcessors) {
2625
if (null != resourceProcessors) {
2726
for (RepresentationModelProcessor<EntityModel<?>> rp : resourceProcessors) {
28-
TypeInformation<?> typeInfo = ClassTypeInformation.from(rp.getClass());
27+
TypeInformation<?> typeInfo = TypeInformation.of(rp.getClass());
2928
TypeInformation<?> domainType = typeInfo.getTypeArguments().get(0);
3029
if (null != repositories.getPersistentEntity(domainType.getType())) {
3130
this.resourceProcessors.add(new DomainTypeResourceProcessor(domainType.getType(), rp));

spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JsonSchemaUnitTests.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import org.junit.jupiter.api.Test;
2121
import org.springframework.data.rest.webmvc.json.JsonSchema.JsonSchemaProperty;
22-
import org.springframework.data.util.ClassTypeInformation;
2322
import org.springframework.data.util.TypeInformation;
2423

2524
/**
@@ -29,7 +28,7 @@
2928
*/
3029
class JsonSchemaUnitTests {
3130

32-
static final TypeInformation<?> type = ClassTypeInformation.from(Sample.class);
31+
static final TypeInformation<?> type = TypeInformation.of(Sample.class);
3332

3433
@Test // DATAREST-492
3534
void considersNumberPrimitivesJsonSchemaNumbers() {

0 commit comments

Comments
 (0)