users@jsonb-spec.java.net

[jsonb-spec users] Re: Integrating JSON-B with Bean Validation

From: Roman Grigoriadi <roman.grigoriadi_at_oracle.com>
Date: Fri, 10 Mar 2017 15:26:11 +0100

Hi,

I like suggested approach with listeners. That way impls may provide
BVListener if they choose to, and impl users may do whatever they like
in something like onDeserializeObject / onDeserializeArray. Not sure if
JsonbAdapter<Object,Object> is nice way to go. Also, if
JsonbAdapter<Object,Object> would work for any object than it appears to
me it must end up with StackOverflowError similar to JsonbAdapter<User,User>

Regards,
Roman

On 03/10/2017 02:57 PM, Dmitry Kornilov wrote:
> Hi,
>
> Let me put my 2 cents here. I think that BV support makes sense on deserialization. The scope of JSONB 1.0 is already defined. We will come back to this conversation when we will start working on the next version of the spec.
>
> Thanks,
> Dmitry
>
> On 09/03/2017, 23:26, "gunnar.morling_at_googlemail.com" <gunnar.morling_at_googlemail.com> wrote:
>
> Hi Romain,
>
> > And also way harder for all frameworks cause in 99% of the cases
> > this will be configurable cause in properties and not usable cause
> > hidden in the framework stacks
>
> I'm not quite following. Integrators doing their own validation
> anyways, such as JAX-RS, wouldn't use this feature in JSON-B. So how
> would things get harder for them?
>
> > a lib using jsonb to read its config. Here it makes sense to
> integrate
> > with BV
>
> Right, that's the use case I'd have in mind. As you say, they could
> validate themselves. Having support for this in JSON-B would just make
> this case a bit simpler.
>
> It'd be
>
> Validator validator = Validation.buildDefaultValidatorFactory()
> .getValidator();
>
> Jsonb jsonb = JsonbBuilder.create();
>
> Person p = jsonb.fromJson( "...", Person.class );
>
> Set<ConstraintViolation<Person>> violations = validator.validate( p
> );
> if ( !violations.isEmpty() ) {
> // throw some exception
> }
>
> Vs.
>
> Jsonb jsonb = JsonbBuilder.create(
> new JsonbConfig()
> .withValidationMode( CALLBACK )
> );
>
> Person p = jsonb.fromJson( "...", Person.class );
>
> So it saves a bit. Nothing more and nothing less :)
>
> Maybe others have thoughts on this, too?
>
> Cheers,
>
> --Gunnar
>
>
>