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();
}
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With