user1549440
user1549440

Reputation: 77

Validating queryparam values jersey

Are there any other ways besides the one below to validate query parameter values i.e. is there a Jersey way to this by mapping to a schema via a wadl. Thank you

@Path("smooth")
@GET
public Response smooth(
    @DefaultValue("blue") @QueryParam("min-color") ColorParam minColor,

public class ColorParam extends Color {
 public ColorParam(String s) {
    super(getRGB(s));
 }

 private static int getRGB(String s) {
    if (s.charAt(0) == '#') {
        try {
            Color c = Color.decode("0x" + s.substring(1));
            return c.getRGB();
        } catch (NumberFormatException e) {
            throw new WebApplicationException(400);

Upvotes: 0

Views: 3124

Answers (1)

Eugenio Cuevas
Eugenio Cuevas

Reputation: 11078

Unfortunately, there is limited support for validation on current JAX-RS version. But according to the draft for JAX-RS 2.0, it will have much better validation handling in the future.

You can see an example of the new features here.

Upvotes: 1

Related Questions