Skip to content
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

Implemented CustomFieldValidator to inject a point of prevention before a source field value is fetched during mapping #266

Closed
wants to merge 3 commits into from

Conversation

gilbertg
Copy link

@gilbertg gilbertg commented Oct 6, 2015

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.

@garethahealy
Copy link
Collaborator

@gilbertg ; can you rebase to force a retest please.

@garethahealy
Copy link
Collaborator

@gilbertg ; any update?

@gilbertg
Copy link
Author

gilbertg commented Jun 22, 2017 via email

gilbertg pushed a commit to gilbertg/dozer that referenced this pull request Jun 23, 2017
@gilbertg
Copy link
Author

gilbertg commented Jun 23, 2017

Hi @garethahealy , failing on a unit test - not sure this is related to my change - either way, perhaps you could eyeball it before I jump into debugging?

If you recognise anything obvious, it'll help.

~gilbert

@garethahealy
Copy link
Collaborator

@gilbertg ; i've noticed this locally - but not seen it on travis before. It seems to have happened from a recent commit. I fixed by adding:

System.setProperty(DozerConstants.CONFIG_FILE_SYS_PROP, "dozer.properties");

to:

https://github.com/DozerMapper/dozer/blob/master/core/src/test/java/org/dozer/AbstractDozerTest.java#L30-L34

@orange-buffalo ; any ideas? it started happening when the singleton PR got merged.

@garethahealy
Copy link
Collaborator

Master branch has now been fixed @gilbertg. If you rebase, the failing tests should now pass.

gilbertg and others added 2 commits July 6, 2017 06:02
…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.
@gilbertg
Copy link
Author

gilbertg commented Jul 6, 2017

@garethahealy yay, finally got a green light. Thanks!

@garethahealy
Copy link
Collaborator

CC @orange-buffalo for review.

Copy link
Contributor

@orange-buffalo orange-buffalo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for huge delay with review, guys. I've put my comments below.

// either deep field map or generic map. The is the most likely
// scenario
mapFromFieldMap(srcObj, destObj, srcFieldValue, fieldMapping);
if (canMapField) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a significant change in core functionality, it should be covered with the tests.

fieldMapped = customFieldMapper.mapField(srcObj, destObj, srcFieldValue, fieldMapping.getClassMap(), fieldMapping);

boolean canMapField = true;
if (customFieldMapper != null && customFieldMapper instanceof CustomFieldMapperAndValidator) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not believe that customFieldMapper instanceof CustomFieldMapperAndValidator is the best way to go here. I would say that "mapping the filed" and "filtering source fields" are two different responsibilities. They should be represented in MapperProcessor via two different objects of two different interfaces.

@garethahealy
Copy link
Collaborator

@gilbertg ; have you had any chance to review comments?

@garethahealy
Copy link
Collaborator

@gilbertg ; i know its been a while, but have you had chance to review the comments?

@gilbertg
Copy link
Author

gilbertg commented Jan 3, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants