<div dir="ltr">Hi Ed... Don't forget that EL has String-based "type coercion" and then there's the basic PropertyEditor stuff from java.beans. Beans binding (JSR 295) was expected to have some notion of conversion IIRC, and that's only the JCP stuff. Spring and others have done conversion frameworks as well, with what are arguably varying degrees of success. I think it's possible to do good, fully-featured Java object conversion, but that (a) it's bigger than can comfortably fit in Bean Validation and (b) it's a shame to limit the feature to conversion when the more generic term "transformation" can encompass the closely-related concept of object *copying*.<div>
<br></div><div style>Shameless self-promotion: see the Therian library [1]. Docs are more or less nonexistent as of now, but Therian provides transformation plumbing so that you can say, e.g.:</div><div style><br></div>
<div style>public Bar convertToBar(@NotNull Foo foo) {</div><div style> final Bar result = therianContext.eval(Convert.to(Bar.class, Positions.readOnly(foo));</div><div style> return result;</div><div style>}</div><div style>
<br></div><div style>I conceived Therian when I was working with JSF so TherianContext extends ELContext. My goal was that it should be easy to plug Therian into JSF for conversions. I haven't actually gotten around to trying this yet, but Therian was based on my experience as a user and developer of the older Morph transformation (etc.) library, and having found it quite easy to plug my Morph transformations into JSF, I don't anticipate any difficulty.</div>
<div style><br></div><div style>Personally, I like Therian's design, but I am also aware that some will find it a bit unwieldy (in the unlikely event that anyone ever even learns of its existence ;P ). I would hope that any broader JSR would be interface-based so as not to preclude the like of Therian being plugged in as a potential implementation, but I can tell you I am exhausted just imagining a specification negotiation in the object transformation space.</div>
<div style><br></div><div style>br,</div><div style>Matt</div><div style><br></div><div style>[1] <a href="https://github.com/mbenson/therian">https://github.com/mbenson/therian</a></div><div style>[2] <a href="http://morph.sourceforge.net/">http://morph.sourceforge.net/</a></div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jul 12, 2013 at 3:27 PM, Edward Burns <span dir="ltr"><<a href="mailto:edward.burns@oracle.com" target="_blank">edward.burns@oracle.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello Volunteers,<br>
<br>
I've been viewing Emmanuel's videos about BV 1.1 and whenever he talks<br>
about Bean Validation and JAX-RS, such as this<br>
<br>
@Path("/user")<br>
class UserResource {<br>
<br>
@Post<br>
@Consumes("application/x-www-form-urlencoded")<br>
public void register(<br>
@NotEmpty @FormParam("firstname") String firstname,<br>
@NotEmpty @FormParam("lastname") String lastname,<br>
@NotNull @Email @FormParam("email") String email) { ... }<br>
}<br>
<br>
I have to ask myself, isn't this missing something? What about<br>
conversion?<br>
<br>
Before Bean Validation, JSF brought type conversion *and* validation to<br>
the table. Now that Bean Validation provides the validation part for<br>
all of JavaEE, isn't it time we think about the other part: type<br>
conversion?<br>
<br>
JSF has an elaborate conversion system with by-type conventions and also<br>
the ability to manually declare that specific converters should be used<br>
for specific values. It's not a far cry to realize that we don't need<br>
to limit ourselves to "String" for these arguments and there is a lot we<br>
could do to enable arbitrary types and have Bean Validation handle the<br>
conversion on the way in.<br>
<br>
JAX-RS also has the javax.ws.rs.ext.ParamConverter facility, which<br>
solves the conversion problem in a JAX-RS specific way.<br>
<br>
Here we have two specs that do conversion. I think it might be useful<br>
to realize that type conversion is really just the first part of<br>
validation, and therefore falls under the responsibility of Bean<br>
Validation.<br>
<br>
Is this worth pursuing?<br>
<br>
Ed<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
_______________________________________________<br>
beanvalidation-dev mailing list<br>
<a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/beanvalidation-dev</a><br>
</font></span></blockquote></div><br></div>