-
-
Notifications
You must be signed in to change notification settings - Fork 927
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
MapStruct does not always use builders in target-object #1997
Comments
@mfriess2 I think that this is the same as #1581 and is caused by projectlombok/lombok#1538. |
Thanks for taking the time to answer but I'm also a bit sad that you closed this issue so fast. 1 ) I am using the proposed solution from #1581 : lombok is after mapstruct (written in the gradle file; I think at execution time it is run reversed: first lombok then mapstruct) To be double-sure, I tried out:
similar to your example https://github.com/mapstruct/mapstruct-examples/blob/master/mapstruct-lombok/build.gradle (but I am using the newer "annotationProcessor" instead of "apt") 2 ) but most important: I de-lomboked the class "CarDetail" just to take Lombok out of the equation and the problem stays the same: the builder is not recognized/used by mapstruct and an uncompilable Mapper is generated Here is the non-lombok class which provokes the same error:
|
Sorry I didn't see that you are using update mapping. In this case we can't use the builder and we would use the setters only. I understand the problem now. Can you try with 1.4.0-SNAPSHOT? I think that there was a similar problem and we have fixed it on master. |
Thanks & sure, I will build it and let you know soon. |
I tried it out with 076f3ba and unfortunately it did not work. |
I can confirm the issue is still in version 1.4.1.Final Any workaround? |
I am also confirming the same bug with the last version 1.4.1.Final. |
@filiphr I can confirm that the problem starts appearing with lombok To reproduce this, adapt the Now, set
I hope this helps investigating the underlying problem. BTW: |
@thunderhook is the problem there with 1.18.16? According to the Lombok changelog 1.18.14 is broken and shouldn't be used |
Ah sorry, yes, this is reproducable with 1.18.16 as well. |
@thunderhook are you by any chance using Java 8 to do the compilation?
|
Thanks for clarification. Yes I am using Java 8. You are right, choosing a higher Java version works at least with maven. Changing to 9 (or 11, or 15, that's what i've tried) also shows From my own test-project using Java 15 this is also reproducable (that was easier than adapting the mapstruct-examples project). with something like @Builder
@Value
public class CustomerDTO {
int customerNumber;
String name;
} IntelliJ generated mapper: @Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2020-11-21T17:47:56+0100",
comments = "version: 1.4.1.Final, compiler: javac, environment: Java 15.0.1 (Oracle Corporation)"
)
public class CustomerMapperImpl implements CustomerMapper {
@Override
public CustomerDTO map(CustomerEntity source) {
if ( source == null ) {
return null;
}
CustomerDTO customerDTO = new CustomerDTO();
// <- compile error java: constructor CustomerDTO in class bug.mapstruct.CustomerDTO cannot be applied to given types;
// required: int,java.lang.String
// found: no arguments
return customerDTO;
}
} Maven generated mapper: @Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2020-11-21T17:51:38+0100",
comments = "version: 1.4.1.Final, compiler: javac, environment: Java 15.0.1 (Oracle Corporation)"
)
public class CustomerMapperImpl implements CustomerMapper {
@Override
public CustomerDTO map(CustomerEntity source) {
if ( source == null ) {
return null;
}
CustomerDTOBuilder customerDTO = CustomerDTO.builder();
customerDTO.customerNumber( (int) source.getCustomerNumber() );
customerDTO.name( source.getName() );
return customerDTO.build();
}
} If I can provide any more info (mvn/idea log), or if this should be an own ticket, please let me know! Edit: Ahh, damn! I wrote the annotation processor configuration wrong. Sorry. It is working now as intended! Thanks! |
I still have this problem. I want to force map construct to use the builder method instead. Model:
Mapper Class:
|
@metao1 seems like you have cross posted this here and in the Lombok issue tracker projectlombok/lombok#2804. MapStruct by default uses builders (if it can see them), see projectlombok/lombok#1538 for more information |
Same problem
|
Hi,
we try to use MapStruct with Lombok builders but MapStruct does not always seem to recognize and use the builders. Our particular problematic case is when the target object has a field which only has a builder.
Used MapStruct version: 1.3.1.FINAL
Used Lombok version: 1.18.10
It would be very helpful for us if you could let us know if this is considered a bug or not.
Looking forward to your feedback!
Here is an example:
Source POJO:
Target POJOs:
Mapper:
MapStruct generates this mapper:
And the compiler fails with:
It would work if MapStruct would generate:
The annotation processor ordering in the Gradle build:
The text was updated successfully, but these errors were encountered: