Open temas-hub opened 8 years ago
Can you post a test case?
The goal is to exclude some items inside the collection during mapping. Collection with name attributes is a field of both Product and ProductBinding classes
`
public ResponseBuilder() {
mapperFactory = new PlatformMapperFactoryImpl.Builder().enableWarmUp(false).build();
mapperFactory.classMap(Product.class, ProductBinding.class)
.byDefault()
.register();
mapperFactory.registerFilter(new AttributeFilter());
}
private class AttributeFilter extends NullFilter<Collection<com.in.AttributeBinding>, Collection<com.out.AttributeBinding>> {
@Override
public boolean filtersSource() {
return true;
}
@Override
public boolean appliesTo(final Property source, final Property destination) {
return super.appliesTo(source, destination) && destination.getName().equals("attributes");
}
@Override
public <S extends Collection<com.in.AttributeBinding>> S filterSource(final S sourceValue, final Type<S> sourceType, final String sourceName,
final Type<?> destType, final String destName, final MappingContext mappingContext) {
Collection<com.in.AttributeBinding> filteredAttributes = new ArrayList<com.in.AttributeBinding>();
if (CollectionUtils.isNotEmpty(sourceValue)) {
for (com.in.AttributeBinding attribute : sourceValue) {
if (allowedAttributeNames.contains(attribute.getName())) {
filteredAttributes.add(attribute);
}
}
}
return (S)filteredAttributes;
}
`
SourceCodeContext.getDestFilter and SourceCodeContext.getSourceFilter return VariableRef with overriden setter() and getter() but ArrayOrCollectionToCollection.generateMappingCode uses MultiOccurrenceVariableRef decorators which dont call these setter/getter
all above causes that Filter.filterSource and Filter.filterDestination are not invoked in the generated code for collection field mapping.