Java Reference
In-Depth Information
This is basically a factory for ParamConverters and is the component that must be scanned
or registered with your Application deployment class.
@Provider
public
public class
class ColorConverterProvider
ColorConverterProvider {
private
private final
final ColorConverter converter = new
new ColorConverter ();
public
public < T > ParamConverter < T > getConverter ( Class < T > rawType ,
Type genericType ,
Annotation [] annotations ) {
iif (! rawType . equals ( Color . class )) return
return null
null ;
return
return converter ;
}
}
In our implementation here, we check to see if the rawType is a Color . If not, return null. If
it is, then return an instance of our ColorConverter implementation. The Annotation[]
parameter for the getConverter() method points to whatever parameter annotations are ap-
plied to the JAX-RS method parameter you are converting. This allows you to tailor the be-
havior of your converter based on any additional metadata applied.
Collections
All the parameter types described in this chapter may have multiple values for the same
named parameter. For instance, let's revisit the @QueryParam example from earlier in this
chapter. In that example, we wanted to pull down a set of customers from a customer data-
base. Let's expand the functionality of this query so that we can order the data sent back by
any number of customer attributes:
GET / customers ? orderBy = last & orderBy = first
In this request, the orderBy query parameter is repeated twice with different values. We can
let our JAX-RS provider represent these two parameters as a java.util.List and inject this
list with one @QueryParam annotation:
import
import java.util.List
java.util.List ;
@Path ( "/customers" )
public
public class
class CustomerResource
CustomerResource {
@GET
@Produces ( "application/xml" )
public
public String getCustomers (
Search WWH ::




Custom Search