[bv-dev] Bean Validation and JAX-RS: conversion too?

Edward Burns edward.burns at oracle.com
Fri Jul 12 16:27:23 EDT 2013


Hello Volunteers,

I've been viewing Emmanuel's videos about BV 1.1 and whenever he talks
about Bean Validation and JAX-RS, such as this

@Path("/user")
class UserResource {

  @Post
  @Consumes("application/x-www-form-urlencoded")
  public void register(
    @NotEmpty @FormParam("firstname") String firstname,
    @NotEmpty @FormParam("lastname") String lastname,
    @NotNull @Email @FormParam("email") String email) { ... }
}

I have to ask myself, isn't this missing something?  What about
conversion?

Before Bean Validation, JSF brought type conversion *and* validation to
the table.  Now that Bean Validation provides the validation part for
all of JavaEE, isn't it time we think about the other part: type
conversion?

JSF has an elaborate conversion system with by-type conventions and also
the ability to manually declare that specific converters should be used
for specific values.  It's not a far cry to realize that we don't need
to limit ourselves to "String" for these arguments and there is a lot we
could do to enable arbitrary types and have Bean Validation handle the
conversion on the way in.

JAX-RS also has the javax.ws.rs.ext.ParamConverter facility, which
solves the conversion problem in a JAX-RS specific way.

Here we have two specs that do conversion.  I think it might be useful
to realize that type conversion is really just the first part of
validation, and therefore falls under the responsibility of Bean
Validation.

Is this worth pursuing?

Ed

-- 


More information about the beanvalidation-dev mailing list