Validating queryparam values jersey

不羁岁月 提交于 2019-12-24 18:18:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!