Skip to content

RestTemplate API is misleading when it comes to url variable passing [SPR-7667] #12323

@spring-projects-issues

Description

@spring-projects-issues

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

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.


Affects: 3.0.4

Referenced from: commits a37a9e8

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions