17
17
18
18
import static org .springframework .hateoas .TemplateVariable .VariableType .*;
19
19
import static org .springframework .hateoas .TemplateVariables .*;
20
- import static org .springframework .hateoas .server .core .EncodingUtils .*;
21
20
import static org .springframework .web .util .UriComponents .UriTemplateVariables .*;
22
21
23
22
import java .lang .annotation .Annotation ;
30
29
import java .util .Iterator ;
31
30
import java .util .List ;
32
31
import java .util .Map ;
32
+ import java .util .Map .Entry ;
33
33
import java .util .Optional ;
34
34
import java .util .concurrent .ConcurrentHashMap ;
35
35
import java .util .function .BiFunction ;
@@ -114,7 +114,9 @@ private static <T extends LinkBuilder> PreparedWebHandler<T> linkTo(Object invoc
114
114
Iterator <Object > classMappingParameters = invocations .getObjectParameters ();
115
115
116
116
while (classMappingParameters .hasNext ()) {
117
- values .put (names .next (), encodePath (classMappingParameters .next ()));
117
+ String name = names .next ();
118
+ TemplateVariable variable = TemplateVariable .segment (name );
119
+ values .put (name , variable .prepareAndEncode (classMappingParameters .next ()));
118
120
}
119
121
120
122
Method method = invocation .getMethod ();
@@ -123,8 +125,8 @@ private static <T extends LinkBuilder> PreparedWebHandler<T> linkTo(Object invoc
123
125
ConversionService resolved = conversionService ;
124
126
125
127
for (HandlerMethodParameter parameter : parameters .getParameterAnnotatedWith (PathVariable .class , arguments )) {
126
- values . put (parameter .getVariableName (),
127
- encodePath (parameter .getValueAsString (arguments , resolved )));
128
+ TemplateVariable variable = TemplateVariable . segment (parameter .getVariableName ());
129
+ values . put ( variable . getName (), variable . prepareAndEncode (parameter .getValueAsString (arguments , resolved )));
128
130
}
129
131
130
132
List <String > optionalEmptyParameters = new ArrayList <>();
@@ -194,24 +196,28 @@ private static void bindRequestParameters(UriComponentsBuilder builder, HandlerM
194
196
195
197
if (value instanceof MultiValueMap ) {
196
198
197
- MultiValueMap <String , String > requestParams = (MultiValueMap <String , String >) value ;
199
+ Map <String , List <?>> requestParams = (Map <String , List <?> >) value ;
198
200
199
- for (Map .Entry <String , List <String >> multiValueEntry : requestParams .entrySet ()) {
200
- for (String singleEntryValue : multiValueEntry .getValue ()) {
201
- builder .queryParam (multiValueEntry .getKey (), encodeParameter (singleEntryValue ));
201
+ for (Entry <String , List <?>> entry : requestParams .entrySet ()) {
202
+ for (Object element : entry .getValue ()) {
203
+ TemplateVariable variable = TemplateVariable .pathVariable (entry .getKey ());
204
+ builder .queryParam (entry .getKey (), variable .prepareAndEncode (element ));
202
205
}
203
206
}
204
207
205
208
return ;
206
-
207
209
}
208
210
209
211
if (value instanceof Map ) {
210
212
211
- Map <String , String > requestParams = (Map <String , String >) value ;
213
+ Map <String , ?> requestParams = (Map <String , ?>) value ;
214
+
215
+ for (Entry <String , ?> entry : requestParams .entrySet ()) {
216
+
217
+ String key = entry .getKey ();
218
+ TemplateVariable variable = TemplateVariable .requestParameter (key );
212
219
213
- for (Map .Entry <String , String > requestParamEntry : requestParams .entrySet ()) {
214
- builder .queryParam (requestParamEntry .getKey (), encodeParameter (requestParamEntry .getValue ()));
220
+ builder .queryParam (key , variable .prepareAndEncode (entry .getValue ()));
215
221
}
216
222
217
223
return ;
@@ -222,18 +228,17 @@ private static void bindRequestParameters(UriComponentsBuilder builder, HandlerM
222
228
}
223
229
224
230
String key = parameter .getVariableName ();
231
+ TemplateVariable variable = TemplateVariable .requestParameter (key );
225
232
226
233
if (value instanceof Collection ) {
227
234
228
235
if (parameter .isNonComposite ()) {
229
-
230
- TemplateVariable variable = TemplateVariable .requestParameter (key );
231
236
builder .queryParam (key , variable .prepareAndEncode (value ));
232
237
233
238
} else {
234
239
for (Object element : (Collection <?>) value ) {
235
240
if (key != null ) {
236
- builder .queryParam (key , encodeParameter (element ));
241
+ builder .queryParam (key , variable . prepareAndEncode (element ));
237
242
}
238
243
}
239
244
}
@@ -247,7 +252,7 @@ private static void bindRequestParameters(UriComponentsBuilder builder, HandlerM
247
252
248
253
} else {
249
254
if (key != null ) {
250
- builder .queryParam (key , encodeParameter (parameter .getValueAsString (arguments , conversionService )));
255
+ builder .queryParam (key , variable . prepareAndEncode (parameter .getValueAsString (arguments , conversionService )));
251
256
}
252
257
}
253
258
}
0 commit comments