users@jsonb-spec.java.net

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

From: <gunnar.morling_at_googlemail.com>
Date: Thu, 9 Mar 2017 11:49:08 +0000 (UTC)

Hi Romain,

> Do you have some more cases?

I think it's mostly manually performed unmarshalling which would
benefit from this:

    Jsonb jsonb = JsonbBuilder.create(
        new JsonbConfig()
            .withValidationMode( CALLBACK ) // or AUTO/NONE as in JPA
            .withValidationGroups( MyBasicConstraints.class )
    );

    // if the call returns, a valid instance is guaranteed
    // otherwise a ConstraintViolationException is raised
    Person personLoaded = jsonb.fromJson( jsonRepresentation,
Person.class );

That way people could configure a validating JsonbBuilder and e.g.
expose it as CDI bean within their application. Wheras no validation
would occur during unmarshalling performed by integrators such as
JAX-RS.

I.e. it'd just be an option to obtain an automatically validating
JsonbBuilder, saving users from writing some glue code.

--Gunnar