You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Brad Johnson <br...@mediadriver.com> on 2016/08/12 15:29:44 UTC

Any good examples of Bean Validation?

http://camel.apache.org/bean-validation.html


The documentation is pretty thin there.  A good code fragment might be
worth 10,000 words in this case.

While I'm using beanio to unmarshal records into beans I think I'd prefer
to leave it out of the validation.  There are a couple of reasons for
that.  The annotations for bean validation might be used in a lot of
different situations including writing out to a database or file system in
addition to reading in.  Second the validation mechanics permit optional
validation rules depending on the situation.

So I'd prefer to just unmarshal and then separately validate.

Probably the most important reason for using the annotations though is that
it makes it easier for business folks to use for specification of canonical
data models for the organization.  And that's also where the optional
annotations for validation become important.  An invoice ID in context 1
might have to be an integer of X length while in context 2 null might be
OK.  So this eases that.


But I don't have a good working example.

Brad

Re: Any good examples of Bean Validation?

Posted by Brad Johnson <br...@mediadriver.com>.
Using CDI I just created a producer that I grab the Hibernate validator now
and run it as it is injected into another bean.  So I can switch contexts
when I need.  Whether I use it in a Camel route or not isn't really too
important.  It works well enough now.

Brad

On Sat, Aug 13, 2016 at 5:03 PM, John D. Ament <jo...@apache.org>
wrote:

> Brad,
>
> Its not clear from your email whether your confusion is how to use bean
> validation or how it integrates with camel.
>
> the integrating with camel part is pretty straight forward.  Assuming that
> the input to the segment of the route is a properly annotated bean, then
> those bean attributes will be validated. and an exception thrown indicating
> validation failed.  What it sounds like your looking for is a way to
> validate the bean based on the context you're in.  That works with groups.
> You may want to have a group for context 1 and another group for context
> 2.  Each validation can be applied to a group, with the default being to
> use the default group.
>
> John
>
> On Fri, Aug 12, 2016 at 11:31 AM Brad Johnson <
> brad.johnson@mediadriver.com>
> wrote:
>
> > http://camel.apache.org/bean-validation.html
> >
> >
> > The documentation is pretty thin there.  A good code fragment might be
> > worth 10,000 words in this case.
> >
> > While I'm using beanio to unmarshal records into beans I think I'd prefer
> > to leave it out of the validation.  There are a couple of reasons for
> > that.  The annotations for bean validation might be used in a lot of
> > different situations including writing out to a database or file system
> in
> > addition to reading in.  Second the validation mechanics permit optional
> > validation rules depending on the situation.
> >
> > So I'd prefer to just unmarshal and then separately validate.
> >
> > Probably the most important reason for using the annotations though is
> that
> > it makes it easier for business folks to use for specification of
> canonical
> > data models for the organization.  And that's also where the optional
> > annotations for validation become important.  An invoice ID in context 1
> > might have to be an integer of X length while in context 2 null might be
> > OK.  So this eases that.
> >
> >
> > But I don't have a good working example.
> >
> > Brad
> >
>

Re: Any good examples of Bean Validation?

Posted by "John D. Ament" <jo...@apache.org>.
Brad,

Its not clear from your email whether your confusion is how to use bean
validation or how it integrates with camel.

the integrating with camel part is pretty straight forward.  Assuming that
the input to the segment of the route is a properly annotated bean, then
those bean attributes will be validated. and an exception thrown indicating
validation failed.  What it sounds like your looking for is a way to
validate the bean based on the context you're in.  That works with groups.
You may want to have a group for context 1 and another group for context
2.  Each validation can be applied to a group, with the default being to
use the default group.

John

On Fri, Aug 12, 2016 at 11:31 AM Brad Johnson <br...@mediadriver.com>
wrote:

> http://camel.apache.org/bean-validation.html
>
>
> The documentation is pretty thin there.  A good code fragment might be
> worth 10,000 words in this case.
>
> While I'm using beanio to unmarshal records into beans I think I'd prefer
> to leave it out of the validation.  There are a couple of reasons for
> that.  The annotations for bean validation might be used in a lot of
> different situations including writing out to a database or file system in
> addition to reading in.  Second the validation mechanics permit optional
> validation rules depending on the situation.
>
> So I'd prefer to just unmarshal and then separately validate.
>
> Probably the most important reason for using the annotations though is that
> it makes it easier for business folks to use for specification of canonical
> data models for the organization.  And that's also where the optional
> annotations for validation become important.  An invoice ID in context 1
> might have to be an integer of X length while in context 2 null might be
> OK.  So this eases that.
>
>
> But I don't have a good working example.
>
> Brad
>