Skip to content

Commit 68b3c19

Browse files
committed
GH-2335 - Remove deprecations introduced until 2.0.
1 parent 7527d2e commit 68b3c19

15 files changed

+303
-229
lines changed

src/main/java/org/springframework/hateoas/AffordanceModel.java

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,6 @@ public interface PayloadMetadata {
204204
*/
205205
Stream<PropertyMetadata> stream();
206206

207-
/**
208-
* @deprecated since 1.4, for removal in 1.5. Prefer {@link #stream()} and selecting individual
209-
* {@code PropertyMetadata} instances yourself.
210-
*/
211-
@Deprecated
212-
default Optional<PropertyMetadata> getPropertyMetadata(String name) {
213-
return stream().filter(it -> it.hasName(name)).findFirst();
214-
}
215-
216207
@Nullable
217208
default Class<?> getType() {
218209
return null;
@@ -235,23 +226,6 @@ static InputPayloadMetadata from(PayloadMetadata metadata) {
235226
: DelegatingInputPayloadMetadata.of(metadata);
236227
}
237228

238-
/**
239-
* Applies the {@link InputPayloadMetadata} to the given target.
240-
*
241-
* @param <T>
242-
* @param target
243-
* @return
244-
* @deprecated since 1.3, prefer setting up the model types via
245-
* {@link AffordanceModel#createProperties(BiFunction)}.
246-
*/
247-
@Deprecated
248-
default <T extends PropertyMetadataConfigured<T> & Named> T applyTo(T target) {
249-
250-
return getPropertyMetadata(target.getName()) //
251-
.map(it -> target.apply(it)) //
252-
.orElse(target);
253-
}
254-
255229
<T extends Named> T customize(T target, Function<PropertyMetadata, T> customizer);
256230

257231
/**
@@ -321,15 +295,6 @@ public Stream<PropertyMetadata> stream() {
321295
return metadata.stream();
322296
}
323297

324-
/*
325-
* (non-Javadoc)
326-
* @see org.springframework.hateoas.AffordanceModel.InputPayloadMetadata#customize(org.springframework.hateoas.AffordanceModel.PropertyMetadataConfigured)
327-
*/
328-
@Override
329-
public <T extends PropertyMetadataConfigured<T> & Named> T applyTo(T target) {
330-
return target;
331-
}
332-
333298
/*
334299
* (non-Javadoc)
335300
* @see org.springframework.hateoas.AffordanceModel.InputPayloadMetadata#customize(org.springframework.hateoas.AffordanceModel.Named, java.util.function.Function)

src/main/java/org/springframework/hateoas/TemplateVariable.java

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,29 @@ public TemplateVariable(String name, TemplateVariable.VariableType type, String
9595
* Static helper to fashion {@link VariableType#PATH_VARIABLE} variables.
9696
*
9797
* @param variable must not be {@literal null} or empty.
98-
* @return
98+
* @return will never be {@literal null}.
9999
* @since 1.1
100100
*/
101101
public static TemplateVariable pathVariable(String variable) {
102-
return new TemplateVariable(variable, VariableType.PATH_VARIABLE);
102+
return new TemplateVariable(variable, VariableType.SIMPLE);
103+
}
104+
105+
/**
106+
* Alias of {@link #pathVariable(String)}.
107+
*
108+
* @param variable must not be {@literal null} or empty.
109+
* @return will never be {@literal null}.
110+
* @since 3.0
111+
*/
112+
public static TemplateVariable simple(String variable) {
113+
return new TemplateVariable(variable, VariableType.SIMPLE);
103114
}
104115

105116
/**
106117
* Static helper to fashion {@link VariableType#REQUEST_PARAM} variables.
107118
*
108119
* @param parameter must not be {@literal null} or empty.
109-
* @return
120+
* @return will never be {@literal null}.
110121
* @since 1.1
111122
*/
112123
public static TemplateVariable requestParameter(String parameter) {
@@ -117,7 +128,7 @@ public static TemplateVariable requestParameter(String parameter) {
117128
* Static helper to fashion {@link VariableType#REQUEST_PARAM_CONTINUED} variables.
118129
*
119130
* @param parameter must not be {@literal null} or empty.
120-
* @return
131+
* @return will never be {@literal null}.
121132
* @since 1.1
122133
*/
123134
public static TemplateVariable requestParameterContinued(String parameter) {
@@ -128,39 +139,33 @@ public static TemplateVariable requestParameterContinued(String parameter) {
128139
* Static helper to fashion {@link VariableType#SEGMENT} variables.
129140
*
130141
* @param segment must not be {@literal null} or empty.
131-
* @return
142+
* @return will never be {@literal null}.
132143
* @since 1.1
133144
*/
134145
public static TemplateVariable segment(String segment) {
135-
return new TemplateVariable(segment, VariableType.SEGMENT);
146+
return new TemplateVariable(segment, VariableType.PATH_SEGMENT);
136147
}
137148

138149
/**
139150
* Static helper to fashion {@link VariableType#FRAGMENT} variables.
140151
*
141152
* @param name must not be {@literal null} or empty.
142-
* @return
153+
* @return will never be {@literal null}.
143154
* @since 1.1
144155
*/
145156
public static TemplateVariable fragment(String name) {
146157
return new TemplateVariable(name, VariableType.FRAGMENT);
147158
}
148159

149-
public static TemplateVariable reservedString(String name) {
150-
return new TemplateVariable(name, VariableType.RESERVED_STRING);
151-
}
152-
153160
/**
154-
* Static helper to fashion {@link VariableType#COMPOSITE_PARAM} variables.
161+
* Static helper to fashion {@link VariableType#RESERVED_STRING} variables.
155162
*
156-
* @param parameter must not be {@literal null} or empty.
157-
* @return
163+
* @param name must not be {@literal null} or empty.
164+
* @return will never be {@literal null}.
158165
* @since 1.1
159-
* @deprecated since 1.4, use actual parameter type and call {@link #composite()} on the instance instead.
160166
*/
161-
@Deprecated
162-
public static TemplateVariable compositeParameter(String parameter) {
163-
return new TemplateVariable(parameter, VariableType.COMPOSITE_PARAM);
167+
public static TemplateVariable reservedString(String name) {
168+
return new TemplateVariable(name, VariableType.RESERVED_STRING);
164169
}
165170

166171
/**
@@ -220,18 +225,6 @@ public boolean hasDescription() {
220225
return StringUtils.hasText(description);
221226
}
222227

223-
/**
224-
* Returns whether the template variable is optional, which means the template can be expanded to a URI without a
225-
* value given for that variable.
226-
*
227-
* @return
228-
* @deprecated since 1.4. No replacement as template variables are never required actually.
229-
*/
230-
@Deprecated
231-
boolean isRequired() {
232-
return !type.isOptional();
233-
}
234-
235228
/**
236229
* Returns whether the given {@link TemplateVariable} is of the same type as the current one.
237230
*
@@ -285,7 +278,6 @@ public String toString() {
285278
}
286279

287280
public String asString() {
288-
289281
return "{" + type.toString() + essence() + "}";
290282
}
291283

@@ -474,32 +466,13 @@ public int hashCode() {
474466
public enum VariableType {
475467

476468
SIMPLE("", ",", false), //
477-
478-
/**
479-
* @deprecated since 1.4, use {@link #SIMPLE} instead.
480-
*/
481-
@Deprecated
482-
PATH_VARIABLE("", ",", true), //
483469
RESERVED_STRING("+", ",", true), //
484470
DOT(".", ".", true), //
485471
REQUEST_PARAM("?", "&", true), //
486472
REQUEST_PARAM_CONTINUED("&", "&", true), //
487-
488473
PATH_SEGMENT("/", "/", true), //
489-
490-
/**
491-
* @deprecated since 1.4, use {@link #PATH_SEGMENT} instead.
492-
*/
493-
@Deprecated
494-
SEGMENT("/", "/", true), //
495474
PATH_STYLE_PARAMETER(";", ";", true), //
496-
FRAGMENT("#", ",", true), //
497-
498-
/**
499-
* @deprecated since 1.4. Use the actual type and call {@link TemplateVariable#composite()}.
500-
*/
501-
@Deprecated
502-
COMPOSITE_PARAM("*", "", true);
475+
FRAGMENT("#", ",", true);
503476

504477
private static final EnumSet<VariableType> COMBINABLE_TYPES = EnumSet.of(REQUEST_PARAM, REQUEST_PARAM_CONTINUED);
505478
static final String DEFAULT_SEPARATOR = ",";
@@ -518,7 +491,6 @@ public String encode(String value) {
518491

519492
switch (this) {
520493
case DOT:
521-
case SEGMENT:
522494
case PATH_SEGMENT:
523495
case PATH_STYLE_PARAMETER:
524496
case REQUEST_PARAM:

src/main/java/org/springframework/hateoas/config/EnableHypermediaSupport.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,6 @@ public List<MediaType> getMediaTypes() {
114114
return this.mediaTypes;
115115
}
116116

117-
/**
118-
* @deprecated since 2.5, in favor of {@link #getMediaTypes()} as a logical media type might have been associated
119-
* with multiple media type identifiers (see {@link #HAL}).
120-
* @return will never be {@literal null}.
121-
*/
122-
@Deprecated(since = "2.5", forRemoval = true)
123-
public MediaType getMediaType() {
124-
return this.mediaTypes.get(0);
125-
}
126-
127117
public String getLocalPackageName() {
128118
return localPackageName;
129119
}

src/main/java/org/springframework/hateoas/server/core/AnnotationMappingDiscoverer.java

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* @author Greg Turnquist
4343
* @author Réda Housni Alaoui
4444
*/
45-
public class AnnotationMappingDiscoverer implements MappingDiscoverer {
45+
public class AnnotationMappingDiscoverer implements MappingDiscoverer, RawMappingDiscoverer {
4646

4747
private final Class<? extends Annotation> annotationType;
4848
private final @Nullable String mappingAttributeName;
@@ -73,50 +73,59 @@ public AnnotationMappingDiscoverer(Class<? extends Annotation> annotation, @Null
7373

7474
/*
7575
* (non-Javadoc)
76-
* @see org.springframework.hateoas.core.MappingDiscoverer#getMapping(java.lang.Class)
76+
* @see org.springframework.hateoas.server.core.MappingDiscoverer#getUriMapping(java.lang.Class)
7777
*/
7878
@Override
7979
@Nullable
80-
public String getMapping(Class<?> type) {
81-
82-
Assert.notNull(type, "Type must not be null!");
83-
84-
String[] mapping = getMappingFrom(findMergedAnnotation(type, annotationType));
85-
86-
return mapping.length == 0 ? null : mapping[0];
80+
public UriMapping getUriMapping(Class<?> type) {
81+
return UriMapping.of(getMapping(type));
8782
}
8883

8984
/*
9085
* (non-Javadoc)
91-
* @see org.springframework.hateoas.core.MappingDiscoverer#getMapping(java.lang.reflect.Method)
86+
* @see org.springframework.hateoas.server.core.MappingDiscoverer#getUriMapping(java.lang.reflect.Method)
9287
*/
9388
@Override
9489
@Nullable
95-
public String getMapping(Method method) {
90+
public UriMapping getUriMapping(Method method) {
9691

9792
Assert.notNull(method, "Method must not be null!");
98-
return getMapping(method.getDeclaringClass(), method);
93+
94+
return getUriMapping(method.getDeclaringClass(), method);
9995
}
10096

10197
/*
10298
* (non-Javadoc)
103-
* @see org.springframework.hateoas.core.MappingDiscoverer#getMapping(java.lang.Class, java.lang.reflect.Method)
99+
* @see org.springframework.hateoas.server.core.MappingDiscoverer#getUriMapping(java.lang.Class, java.lang.reflect.Method)
104100
*/
105101
@Override
106102
@Nullable
107-
public String getMapping(Class<?> type, Method method) {
103+
public UriMapping getUriMapping(Class<?> type, Method method) {
108104

109-
Assert.notNull(type, "Type must not be null!");
110-
Assert.notNull(method, "Method must not be null!");
105+
var mapping = getMapping(type, method);
106+
107+
return mapping == null ? null : UriMapping.of(cleanup(mapping));
108+
}
111109

112-
String[] mapping = getMappingFrom(findMergedAnnotation(method, annotationType));
110+
/*
111+
* (non-Javadoc)
112+
* @see org.springframework.hateoas.server.core.RawMappingDiscoverer#getMapping(java.lang.Class, java.lang.reflect.Method)
113+
*/
114+
@Override
115+
public @Nullable String getMapping(@Nullable Class<?> type, @Nullable Method method) {
116+
117+
String[] mapping = method == null ? new String[0] : getMappingFrom(findMergedAnnotation(method, annotationType));
113118
String typeMapping = getMapping(type);
114119

115120
if (mapping.length == 0) {
116121
return typeMapping;
117122
}
118123

119-
return cleanup(typeMapping == null || "/".equals(typeMapping) ? mapping[0] : join(typeMapping, mapping[0]));
124+
var result = typeMapping == null || "/".equals(typeMapping)
125+
? mapping[0]
126+
: join(typeMapping, mapping[0]);
127+
128+
return cleanup(result);
120129
}
121130

122131
/**
@@ -179,6 +188,17 @@ public String[] getParams(Method method) {
179188
return params == null ? new String[0] : params;
180189
}
181190

191+
private @Nullable String getMapping(@Nullable Class<?> type) {
192+
193+
if (type == null) {
194+
return null;
195+
}
196+
197+
String[] mapping = getMappingFrom(findMergedAnnotation(type, annotationType));
198+
199+
return mapping.length == 0 ? null : mapping[0];
200+
}
201+
182202
private String[] getMappingFrom(@Nullable Annotation annotation) {
183203

184204
if (annotation == null) {

src/main/java/org/springframework/hateoas/server/core/CachingMappingDiscoverer.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*/
3636
public class CachingMappingDiscoverer implements MappingDiscoverer {
3737

38-
private static final Map<String, String> MAPPINGS = new ConcurrentReferenceHashMap<>();
38+
private static final Map<String, UriMapping> MAPPINGS = new ConcurrentReferenceHashMap<>();
3939
private static final Map<String, Collection<HttpMethod>> METHODS = new ConcurrentReferenceHashMap<>();
4040
private static final Map<String, String[]> PARAMS = new ConcurrentReferenceHashMap<>();
4141
private static final Map<String, List<MediaType>> CONSUMES = new ConcurrentReferenceHashMap<>();
@@ -52,38 +52,38 @@ public static CachingMappingDiscoverer of(MappingDiscoverer delegate) {
5252

5353
/*
5454
* (non-Javadoc)
55-
* @see org.springframework.hateoas.core.MappingDiscoverer#getMapping(java.lang.Class)
55+
* @see org.springframework.hateoas.server.core.MappingDiscoverer#getUriMapping(java.lang.Class)
5656
*/
5757
@Nullable
5858
@Override
59-
public String getMapping(Class<?> type) {
59+
public UriMapping getUriMapping(Class<?> type) {
6060

6161
String key = key(type, null);
6262

63-
return MAPPINGS.computeIfAbsent(key, __ -> delegate.getMapping(type));
63+
return MAPPINGS.computeIfAbsent(key, __ -> delegate.getUriMapping(type));
6464
}
6565

6666
/*
6767
* (non-Javadoc)
68-
* @see org.springframework.hateoas.core.MappingDiscoverer#getMapping(java.lang.reflect.Method)
68+
* @see org.springframework.hateoas.server.core.MappingDiscoverer#getUriMapping(java.lang.reflect.Method)
6969
*/
7070
@Nullable
7171
@Override
72-
public String getMapping(Method method) {
73-
return MAPPINGS.computeIfAbsent(key(method), __ -> delegate.getMapping(method));
72+
public UriMapping getUriMapping(Method method) {
73+
return MAPPINGS.computeIfAbsent(key(method), __ -> delegate.getUriMapping(method));
7474
}
7575

7676
/*
7777
* (non-Javadoc)
78-
* @see org.springframework.hateoas.core.MappingDiscoverer#getMapping(java.lang.Class, java.lang.reflect.Method)
78+
* @see org.springframework.hateoas.server.core.MappingDiscoverer#getUriMapping(java.lang.Class, java.lang.reflect.Method)
7979
*/
8080
@Nullable
8181
@Override
82-
public String getMapping(Class<?> type, Method method) {
82+
public UriMapping getUriMapping(Class<?> type, Method method) {
8383

8484
String key = key(type, method);
8585

86-
return MAPPINGS.computeIfAbsent(key, __ -> delegate.getMapping(type, method));
86+
return MAPPINGS.computeIfAbsent(key, __ -> delegate.getUriMapping(type, method));
8787
}
8888

8989
/*

0 commit comments

Comments
 (0)