Java Reference
In-Depth Information
...
}
}
Here, we've used
@DefaultValue
to specify a default start index of
0
and a default dataset
size of
10
. JAX-RS will use the string conversion rules to convert the string value of the
@DefaultValue
annotation into the desired Java type.
@Encoded
URI template, matrix, query, and form parameters must all be encoded by the HTTP specific-
ation. By default, JAX-RS decodes these values before converting them into the desired Java
types. Sometimes, though, you may want to work with the raw encoded values. Using the
@javax.ws.rs.Encoded
annotation gives you the desired effect:
@GET
@Produces
(
"application/xml"
)
public
public
String get
(
@Encoded
@QueryParam
(
"something"
)
String str
) {...}
Here, we've used the
@Encoded
annotation to specify that we want the encoded value of the
something
query parameter to be injected into the
str
Java parameter. If you want to work
solely with encoded values within your Java method or even your entire class, you can an-
notate the method or class with
@Encoded
and only encoded values will be used.
Wrapping Up
In this chapter, we examined how to use JAX-RS injection annotations to insert bits and
pieces of an HTTP request à la carte into your JAX-RS resource method parameters. While
data is represented as strings within an HTTP request, JAX-RS can automatically convert
this data into the Java type you desire, provided that the type follows certain constraints.
These features allow you to write compact, easily understandable code and avoid a lot of the
boilerplate code you might need if you were using other frameworks like the servlet specific-
ation. You can test-drive the code in this chapter by flipping to
Chapter 20
.
[
4
]
For more information, see
http://www.ietf.org/rfc/rfc2109.txt
.

