Filtering mapping based on field names

112 views
Skip to first unread message

Masoud Mohammadi

unread,
Apr 29, 2014, 4:50:19 PM4/29/14
to model...@googlegroups.com
Hi, 

    Is it possible to filter (or ignore) mappings of certain class fields based on field name?

I.E: 
class Source { 
     private A field1;
     private B field2;
     protected Source(){}
     public Source(A param1,B param2){...}
// Note: no setter methods
}

class Target {
     private A filed1;
     protected Target(){}
     public Target(A param1){...}
// Note: no setter methods
}

modelMapper.getConfiguration()
//Does something like this exist?
                      .fieldFilter((sourceObj,sourceField) -> { return !sourceField.getName().equals("field2")}

I would like to make the mapping as strict as possible but yet have the options to configure which fields to ignore.  

Following is my currently configuration.
        modelMapper.getConfiguration()
                .setFieldMatchingEnabled(true)
                .setMatchingStrategy(MatchingStrategies.STRICT)
                .setFieldAccessLevel(Configuration.AccessLevel.PRIVATE);

Thank you in advance for taking the time to view this question.


Jonathan Halterman

unread,
Jun 6, 2014, 7:08:31 PM6/6/14
to model...@googlegroups.com
Hi Masoud,

Field support has been added to ModelMapper for the upcoming 0.7.0 release which will be out in a few days. Fields can be skipped via:

skip(destination.fieldName);

Or conditionally skipped:

when(someCondition).skip(source.fieldName, destination.fieldName);

This will skip the mapping from source.fieldName to destination.fieldName when someCondition applies. This new functionality should be released in the next few days.

Cheers,
Jonathan


--
You received this message because you are subscribed to the Google Groups "modelmapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modelmapper...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

vianney...@dooapp.com

unread,
Dec 10, 2015, 11:22:17 AM12/10/15
to modelmapper
Hi,

In this example the field is private and not directly accessible. It is possible to skip a such field ?
Reply all
Reply to author
Forward
0 new messages