Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-projects-issues opened this issue Oct 20, 2010 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

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

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

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?

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

Added formatting

@spring-projects-issues spring-projects-issues added type: bug A general bug in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0.5 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants