I try to validate beans by Hibernate Validator. It should be programable and based on a JSON config file. data models:
class A {
field,
other fields
}
class B {
class A a,
other fields
}
class C {
class A a,
other fields
}
class D {
class B b,
class C c,
other fields
}
Validate D based on a JSON config file. The config file wants to validate the following: D.b.a.field should not be null. D.c.a.field is nullable.
Using program way, I set the validation like this:
constraintMapping
.type( D.class )
.property( "b", FIELD )
.constraint( new NotNullDef() )
.valid()
.type( B.class )
.property( "a", FIELD )
.constraint( new NotNullDef() )
.valid()
.type ( A.class )
.property( "field", FIELD )
.constraint( new NotNullDef() );
Now, the A.field has been set to not null validator, but the problem is, now the D.c.a.filed also cannot be null.
This is just an example, I absolutely don't want to change the data models.