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

[BUG] lombok-mapstruct-binding incorrectly removes the "is" prefix #3735

Open
cocoliliace opened this issue Aug 30, 2024 · 0 comments
Open

Comments

@cocoliliace
Copy link

cocoliliace commented Aug 30, 2024

Describe the bug
When explicitly marking a target in MapStruct, if the target is a boolean with the "is" prefix, and the target class uses lombok's @Getter and @Setter on the field, MapStruct fails to compile.

For example,

@Mapping(target = "isPublic", source = "isPublic")
CarDto toCarDto(Car car);

would throw

No property named "isPublic" exists in source parameter(s). Did you mean "public"?

I suspect MapStruct is attempting to guess the original field name by removing the "is" from lombok, but it fails to take in account that lombok does not add the "is" prefix if the field already has it (eg. the "isPublic" field in our case).

Setting lombok.getter.noIsPrefix=true in lombok.config fixes the issue.

To Reproduce

@Data
public class CarDto {
    boolean isPublic;
}

@Data
public class Car {
    boolean isPublic;
}

@Mapper
public interface CarMapper {
    @Mapping(target = "isPublic", source = "isPublic")
    CarDto toCarDto(Car car);
}

With Mapstruct and the lombok-mapstruct-binding plugin:

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-compiler-plugin</artifactId>
	<configuration>
		<annotationProcessorPaths>
			<path>
				<groupId>org.mapstruct</groupId>
				<artifactId>mapstruct-processor</artifactId>
				<version>${org.mapstruct.version}</version>
			</path>
			<path>
				<groupId>org.projectlombok</groupId>
				<artifactId>lombok</artifactId>
			</path>
			<path>
				<groupId>org.projectlombok</groupId>
				<artifactId>lombok-mapstruct-binding</artifactId>
				<version>0.2.0</version>
			</path>
		</annotationProcessorPaths>
		<showWarnings>true</showWarnings>
	</configuration>
</plugin>

Expected behavior
The above code should compile.

Version info (please complete the following information):

  • Lombok 1.18.34
  • javac 21.0.4
  • Eclipse 4.32.0
  • Mapstruct 1.5.5.Final and 1.6.0
  • lombok-mapstruct-binding 0.2.0

Additional context
Happens on both MacOS and Fedora Linux

@cocoliliace cocoliliace changed the title [BUG] mapstruct-lombok-binding incorrectly removes the "is" prefix [BUG] lombok-mapstruct-binding incorrectly removes the "is" prefix Aug 30, 2024
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

1 participant