-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional strict handling of BeanMapper mappings #75
Comments
The approach will be the following:
When the mapping is made for the first time (this can be checked against the cache), the strict rules must be checked:
On top of these settings, it must be possible to preregister source/target pairs and check these when the BeanMapper bean is created. This is functionality which is similar to Hibernate's ddl-auto=validate. BeanMapper starter can make use of the preregistrations to component scan annotations which it will supply (BeanMapsTo for Form and BeanMapsFrom for Result). Classes with these annotations and their counterparts will be registered as pairs. As soon as the bean is created, the checks on these pairs will be performed, any failure of which results in an exception. |
Issue #75. Added ability to add pairs of classes which must be checked as soon as a BeanMapper instance is created. As soon as a BeanMapper instance is created (method build on BeanMapperBuilder), it will validate its sets of Bean pairs. The strict side will be verified so that all properties contain matching properties on the other side. If this is not the case, an exception will be thrown. The exception contains information on all the Bean pairs and every mismatching property. Within BeanMatchStore, there are two routes for a BeanMatch to be created. The main route is the existing one where a match is set up runtime (or reused if already existing). The second route is the pre-bean instantiation validation where are registered strict bean pairs are validated upfront. In both cases the validation is done at the time of BeanMatch construction. The Bean pair validation routine makes use of the underlying exceptions to report them back all at once. Configuration allows the setting of the strict mapping convention. If this is enabled, any source class with the set suffix (default 'Form') will be considered strict. Same counts for any target class with the set suffix (default 'Result'). This means that the opposing side must have matches for all properties. If these are missing, this will result in an exception. The principle is basically the same as strict bean pairs, but runtime instead of before bean instantiation. Note that strict mapping convention is disabled for dynamically generated classes (downsizeSource/downsizeTarget), since these concepts rely on the fact that no full match can be supplied.
Issue #75. Added ability to add pairs of classes which must be checked as soon as a BeanMapper instance is created. As soon as a BeanMapper instance is created (method build on BeanMapperBuilder), it will validate its sets of Bean pairs. The strict side will be verified so that all properties contain matching properties on the other side. If this is not the case, an exception will be thrown. The exception contains information on all the Bean pairs and every mismatching property. Within BeanMatchStore, there are two routes for a BeanMatch to be created. The main route is the existing one where a match is set up runtime (or reused if already existing). The second route is the pre-bean instantiation validation where are registered strict bean pairs are validated upfront. In both cases the validation is done at the time of BeanMatch construction. The Bean pair validation routine makes use of the underlying exceptions to report them back all at once. Configuration allows the setting of the strict mapping convention. If this is enabled, any source class with the set suffix (default 'Form') will be considered strict. Same counts for any target class with the set suffix (default 'Result'). This means that the opposing side must have matches for all properties. If these are missing, this will result in an exception. The principle is basically the same as strict bean pairs, but runtime instead of before bean instantiation. Note that strict mapping convention is disabled for dynamically generated classes (downsizeSource/downsizeTarget), since these concepts rely on the fact that no full match can be supplied.
Currently, the following convention applies within 42:
At the moment this is not enforced. The consequence of this lenient approach is that mappings may fail silently.
It would be beneficial if BeanMapper enforces that all Form/Result properties are mappable to/from an Entity. If this happens at mapping time, a proper error is generated, instead of failing silently.
The text was updated successfully, but these errors were encountered: