问题
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);
回答1:
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.
来源:https://stackoverflow.com/questions/11770329/validating-queryparam-values-jersey