Skip to content

Missing Type import for Map<k,v> when providing custom mapper #955

@simontrudeau

Description

@simontrudeau

When declaring a mapper like so using MapStruct version 1.1.0.CR2:

Mapper:

@Mapper(uses = {personMapper.class})
public interface CarMapper {
	SuperCar mapCar(Car source, @MappingTarget SuperCar destination);
}

Custom Mapper

@Component
public class EslUserCustomFieldMapMergeMapper {

public Map<String,Person> merge(Map<String,Person> source, @MappingTarget Map<String,Person> destination){
		source.entrySet().forEach(entry -> destination.put(entry.getKey(), entry.getValue()));
		return destination;
	}
}

Car containing a Map of Person

public class Car {
    private Map<String, Person> persons = new HashMap<String, Person>();
...
}

The generate code is missing import for type Person. The generate code (CarMapperImpl.java) contains the following and is missing import for the type Person, thus it doesn't compile:

...
if ( destination.getPersons() == null ) {
            destination.setPersons( new HashMap<String, Person>() );
        }
carMapper.merge( source.getPersons(), destination.getPersons() );
...

Is it possible to add a hint or something so that the generator knows to add the import for the type Person?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions