Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented CustomFieldValidator to inject a point of prevention befo…
…re a source field value is fetched during mapping A custom field validator is usually in conjunction with a CustomFieldMapper when implementing the CustomFieldMapperAndValidator interface. Use this when you want logic to prevent source field values being fetched. e.g. when checking lazy loaded relationships in an ORM If a custom field validator is specified, Dozer will invoke this class when performing all field mappings. If false is returned from the call the source field value will never be fetched, and subsequently the field will never be mapped.
- Loading branch information
Showing
3 changed files
with
53 additions
and
15 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
core/src/main/java/org/dozer/CustomFieldMapperAndValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.dozer; | ||
|
||
/** | ||
* Public custom field validator and mapper interface. | ||
* Implement this interface on your custom field mapper if you want to implement both CustomFieldMapper & CustomFieldValidator functions | ||
* | ||
* @author Gilbert Grant | ||
*/ | ||
public interface CustomFieldMapperAndValidator extends CustomFieldMapper, CustomFieldValidator {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.dozer; | ||
|
||
import org.dozer.classmap.ClassMap; | ||
import org.dozer.fieldmap.FieldMap; | ||
|
||
/** | ||
* Public custom field validator interface. A custom field validator is usually in conjunction with a CustomFieldMapper | ||
* when implementing the CustomFieldMapperAndValidator interface. | ||
* Use this when you want logic to prevent source field values being fetched | ||
* e.g. when checking lazy loaded relationships in an ORM | ||
* | ||
* <p> | ||
* If a custom field validator is specified, Dozer will invoke this class when performing all field mappings. If false is | ||
* returned from the call the source field value will never be fetched, and subsequently the field will never be mapped. | ||
* | ||
* @author Gilbert Grant | ||
*/ | ||
public interface CustomFieldValidator { | ||
boolean canMapField(Object source, Object destination, ClassMap classMap, FieldMap fieldMapping); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters