Java Reference
In-Depth Information
@BeanParam
The
@BeanParam
annotation is something new added in the JAX-RS 2.0 specification. It al-
lows you to inject an application-specific class whose property methods or fields are annot-
ated with any of the injection parameters discussed in this chapter. For example, take this
class:
public
public class
class
CustomerInput
CustomerInput
{
@FormParam
(
"first"
)
String firstName
;
@FormParam
(
"list"
)
String lastName
;
@HeaderParam
(
"Content-Type"
)
String contentType
;
public
public
String
getFirstName
() {...}
....
}
Here we have a simple POJO (Plain Old Java Object) that contains the first and last names of
a created customer, as well as the content type of that customer. We can have JAX-RS create,
initialize, and inject this class using the
@BeanParam
annotation:
@Path
(
"/customers"
)
public
public class
class
CustomerResource
CustomerResource
{
@POST
public
public
void
void
createCustomer
(
@BeanParam
CustomerInput newCust
) {
...
}
}
The JAX-RS runtime will introspect the
@BeanParam
parameter's type for injection annota-
tions and then set them as appropriate. In this example, the
CustomerInput
class is interes-
ted in two form parameters and a header value. This is a great way to aggregate information
instead of having a long list of method parameters.
Common Functionality
Each of these injection annotations has a common set of functionality and attributes. Some
can automatically be converted from their string representation within an HTTP request into