-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
The following mapper:
import org.mapstruct.Mapper;
class Override {}
class OverrideDto {}
class Car {
public Override override;
}
class CarDto {
public OverrideDto override;
}
@Mapper
interface Issue3904Mapper {
CarDto map(Car car);
OverrideDto map(Override override);
}generates:
import javax.annotation.processing.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2025-07-26T10:41:47+0200",
comments = "version: 1.6.0, compiler: javac, environment: Java 21.0.1 (Oracle Corporation)"
)
class Issue3904MapperImpl implements Issue3904Mapper {
@Override
public CarDto map(Car car) {
if ( car == null ) {
return null;
}
CarDto carDto = new CarDto();
carDto.override = map( car.override );
return carDto;
}
@Override
public OverrideDto map(Override override) { // Incompatible types
if ( override == null ) {
return null;
}
OverrideDto overrideDto = new OverrideDto();
return overrideDto;
}
}Override needs to get a fully qualified name, which it currently does not.
Interesting note: I also tried this with Generated (which could also clash) but this got a qully qualified name.
Another option would be to write @java.lang.Override.
Discussed in #3904
Originally posted by trico-tillster July 23, 2025
I've 1 object to be mapped to another, if one of them contains a object called Override compiler fails.
This happens because generated code adds the @Override annotation to the implementation method, and compiler gets confused with the import class.
I've tried to search for a config to manipulate the generated annotation, something like updating it to @java.lang.Override, but I was not able.
I'm also not able to change the model Override class name to other, because this is a generated code from an external json schema.
Thought it would be helpful to mention this here.
Any clues how to solve this?