Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map Target object with no source object using MapStruct

Tags:

mapstruct

I want to map a Target object with no source object using MapStruct. I tried it, but getting the below error.

Can't generate mapping method with no input arguments

Mapper code

public interface MyMapper {
@Mapping(target="student.courseName", constant="Master in Science")
Target map();
}
like image 438
Sai A Avatar asked Oct 19 '25 22:10

Sai A


1 Answers

As you can see this is not supported. And why would you do that? Why not just write your own method?

That aside, you can theoretically try passing a dummy parameter that won't be mapped.

public interface MyMapper {
    @Mapping(target="student.courseName", constant="Master in Science")
    Target map(Integer dummy);
}
like image 107
Filip Avatar answered Oct 26 '25 15:10

Filip



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!