You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The API on the RestTemplate is misleading when it comes to variable passing
When Map<String,?> is used you would expect it to be possible to send an impl of HashMap<String,Integer> without any issues , but since expand of URI code is
Object[] values = new String[this.variableNames.size()];
for (int i = 0; i < this.variableNames.size(); i++) {
String name = this.variableNames.get(i);
if (!uriVariables.containsKey(name)) {
throw new IllegalArgumentException("'uriVariables' Map has no value for '" + name + "'");
}
values[i] = uriVariables.get(name);
}
you cannot ever send anything else but String.
The API should in my opinion be e.g
public <T> T getForObject(String url, Class<T> responseType, Map<String, ?> urlVariables) ---> public <T> T getForObject(String url, Class<T> responseType, Map<String, String> urlVariables)
To make it clear that String is the only allowed parameter value and to make impl take care of String conversion.
Arjen, could we simply process the values as an Object array there, or alternatively call toString() on every value before setting them as an array element?
Rune Lien opened SPR-7667 and commented
The API on the RestTemplate is misleading when it comes to variable passing
When Map<String,?> is used you would expect it to be possible to send an impl of HashMap<String,Integer> without any issues , but since expand of URI code is
you cannot ever send anything else but String.
The API should in my opinion be e.g
public <T> T getForObject(String url, Class<T> responseType, Map<String, ?> urlVariables) ---> public <T> T getForObject(String url, Class<T> responseType, Map<String, String> urlVariables)
To make it clear that String is the only allowed parameter value and to make impl take care of String conversion.
Affects: 3.0.4
Referenced from: commits a37a9e8
The text was updated successfully, but these errors were encountered: