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

An error occurs depending on the location of the collection parameter. #2276

Closed
DaeAkin opened this issue Nov 16, 2020 · 2 comments
Closed

Comments

@DaeAkin
Copy link

DaeAkin commented Nov 16, 2020

DemoDto.java

@Getter
@Setter
@ToString
public class DemoDto {
    private String userId;
    private String name;
}

DemoEntity.java

@Getter
@Setter
@ToString
public class DemoEntity {
    private String userId;
    private String name;

    List<String> someList;
}

DemoMapper.java

@Mapper(componentModel = "spring",
        nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
public interface DemoMapper {
    DemoEntity toDto(List<String> someList,DemoDto demoDto);
}

when compile this class, An error occurs : error: Can't generate mapping method from iterable type to non-iterable type.
DemoEntity toDto(List someList,DemoDto demoDto);

but I change the position List<String> someList to behind, it works.

@Mapper(componentModel = "spring",
        nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
public interface DemoMapper {
    DemoEntity toDto(DemoDto demoDto,List<String> someList);
}

I'm using this :

    compileOnly group: 'org.mapstruct', name: 'mapstruct', version: '1.3.1.Final'
    annotationProcessor group: 'org.mapstruct', name: 'mapstruct-processor', version: '1.3.1.Final'

    compileOnly  group: 'org.projectlombok', name: 'lombok', version: '1.18.12'
    annotationProcessor   group: 'org.projectlombok', name: 'lombok', version: '1.18.12'

Is it Issue? Thanks.

@filiphr
Copy link
Member

filiphr commented Nov 16, 2020

This is a duplicate of #607 which was recently implemented and will be part of 1.5.0.

In order to make it work in your example you'll have to swap the source paremters.

e.g.

@Mapper(componentModel = "spring",
        nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
public interface DemoMapper {
    DemoEntity toDto(DemoDto demoDto, List<String> someList);
}

@DaeAkin
Copy link
Author

DaeAkin commented Nov 16, 2020

Thanks for answering.

@DaeAkin DaeAkin closed this as completed Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants