mapstruct
mapstruct copied to clipboard
Ignore fields by Suffix or type
Use case
Hello,
I am using Mapstruct with Avro, and the generated class has builder fields that Mapstruct is trying to map.
Because of that, in every mapper, I have to ignore those fields:
import com.my.event.MyEventMapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
@Mapper(
config = EventConfig.class)
public interface AvroMyEventMapper {
@Override
@Mapping(target = "metadata", source = "data")
@Mapping(target = "eventPayload", source="data")
@Mapping(target = "snapshotPayload", source = "booking")
@Mapping(target = "snapshotPayloadBuilder", ignore = true)
@Mapping(target = "metadataBuilder", ignore = true)
@Mapping(target = "eventPayloadBuilder", ignore = true)
AvroRefundRequestedEvent map(Data data);
}
Do you know which trick I can implement to avoid that ?
I tried with SPI by trying to ignore type which ends with Builder but without success for now, is SPI would it be the good way to do it ?
Thank you !
Generated Code
No response
Possible workarounds
No response
MapStruct Version
No response
@AlEmerich did you implement a custom AccessorNamingStrategy? You can check the existing type and only if it extends something from Avro you can exclude those methods?
Can you perhaps provide some example with what you tried?