Skip to content

Commit

Permalink
Updated the Request object to enable type capture on the attribute(St…
Browse files Browse the repository at this point in the history
…ring) method.
  • Loading branch information
jkwatson committed Jul 19, 2014
1 parent 1ecd428 commit eec4896
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main/java/spark/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ public void attribute(String attribute, Object value) {
* @param attribute The attribute value or null if not present
* @return the value for the provided attribute
*/
public Object attribute(String attribute) {
return servletRequest.getAttribute(attribute);
public <T> T attribute(String attribute) {
return (T) servletRequest.getAttribute(attribute);
}


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spark/webserver/RequestWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void attribute(String attribute, Object value) {
}

@Override
public Object attribute(String attribute) {
public <T> T attribute(String attribute) {
return delegate.attribute(attribute);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public static void main(String[] args) {
});

after("/hi", (request, response) -> {
Object foo = request.attribute("foo");
String foo = request.attribute("foo");
response.body(asXml("foo", foo));
});
}

private static String asXml(String name, Object value) {
private static String asXml(String name, String value) {
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><" + name + ">" + value + "</" + name + ">";
}

Expand Down

0 comments on commit eec4896

Please sign in to comment.