You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 12, 2020. It is now read-only.
An issue I encountered when integrating RAVE was boilerplate for dealing with nested models. Let's say I have a class, ModelA, that contains an instance of ModelB. For an instance of ModelA to be considered valid, its instance of ModelB must also be valid.
@Validated(factory = SampleFactory.class)
publicclassModelA {
privateModelBmModelB;
@MustBeTruepublicbooleanisModelBValid() {
try {
Rave.getInstance().validate(mModelB);
returntrue;
} catch (RaveExceptione) {
returnfalse;
}
}
}
@Validated(factory = SampleFactory.class)
publicclassModelB {
// ModelB can have its own arbitrary validation criteria, including nested models
}
There are some issues with the above code:
This doesn't scale well as ModelA accumulates more nested models. Each one requires its own @MustBeTrue-annotated getter, which must have the same code duplicated.
Every model class that contains an instance of ModelB must have the same boilerplate.
I think the solution to this issue is to have default, recursive validation of fields. The logic would be something like:
voidvalidate(Objectmodel)
forfieldinmodel:
iffieldissupported:
validate(field)
// current logic here for validation of additional getters
An issue I encountered when integrating RAVE was boilerplate for dealing with nested models. Let's say I have a class,
ModelA, that contains an instance ofModelB. For an instance ofModelAto be considered valid, its instance ofModelBmust also be valid.There are some issues with the above code:
ModelAaccumulates more nested models. Each one requires its own@MustBeTrue-annotated getter, which must have the same code duplicated.ModelBmust have the same boilerplate.I think the solution to this issue is to have default, recursive validation of fields. The logic would be something like: