vadbch / orika

Automatically exported from code.google.com/p/orika
0 stars 0 forks source link

Filter is not applied on source list. #186

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create filter for a list
2. Declare mapping for a beans on which the filter should be applied
3. Apply the mapping

What is the expected output? What do you see instead?
I expected the mapping on the destination list to be based on the filtered 
source list.
Instead the mapping is performed on the source list without filter

What version of the product are you using? On what operating system?
Orika 1.4.5 on MacOS

Please provide any additional information below.
Generated code for the mapping looks like this:

        if (((ma.glasnost.orika.Filter) usedFilters[0]).shouldMap(
                ((ma.glasnost.orika.metadata.Type) usedTypes[0]), "name",
                ((java.util.List) source.name),
                ((ma.glasnost.orika.metadata.Type) usedTypes[1]), "first",
                ((java.util.List) destination.first), mappingContext)) {
            if (!(((java.util.List) source.name) == null)) {

                java.util.List new_first = ((java.util.List) new java.util.ArrayList(
                        ((java.util.List) ((ma.glasnost.orika.Filter) usedFilters[0])
                                .filterSource(
                                        ((java.util.List) source.name),
                                        ((ma.glasnost.orika.metadata.Type) usedTypes[0]),
                                        "name",
                                        ((ma.glasnost.orika.metadata.Type) usedTypes[1]),
                                        "first", mappingContext)).size()));

                new_first.addAll(mapperFacade.mapAsList(
                        ((java.util.List) source.name),
                        ((ma.glasnost.orika.metadata.Type) usedTypes[2]),
                        ((ma.glasnost.orika.metadata.Type) usedTypes[3]),
                        mappingContext));
                destination.first = new_first;
            } else {
                if (!(((java.util.List) destination.first) == null)) {
                    destination.first = null;
                }
                ;
            }
        }

It seems the filtered list is used only to initialize the size of the 
destination array list. The actual mapping is using source.name instead of 
((ma.glasnost.orika.Filter) usedFilters[0])
                            .
                                        ((java.util.List) source.name),
                                        ((ma.glasnost.orika.metadata.Type) usedTypes[0]),
                                        "name",
                                        ((ma.glasnost.orika.metadata.Type) usedTypes[1]),
                                        "first", mappingContext))

Original issue reported on code.google.com by guillaum...@appdirect.com on 18 Dec 2014 at 3:35

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks !

Original comment by elaat...@gmail.com on 20 Dec 2014 at 5:34