How do I completely disable using "builders" in MapStruct? I don't want to use them at all as they are causing all kinds of issues for me.
I created the service file under META-INF (I would prefer a way to assign it to the mapping builder= but I did not see any examples how to do it right in code).
It is still trying to use Immutables "builder" instance instance of the "ModifiableXXX" instance I want to map to. I'd even take a way of forcing it to the modifiable type if that is available.
In another mapping, using an update the ModifiableXXX (with @AfterMapping and @MappingTarget) approach works.
My mapper looks like this right now:
@Mapper
public interface MongoProjectMapper
{
ModifiableProject mapModel(MongoProject project);
@AfterMapping
ModifiableProject updateProject(MongoEntity e, @MappingTarget ModifiableProject p);
}
Annotation Type AfterMappingMarks a method to be invoked at the end of a generated mapping method, right before the last return statement of the mapping method. The method can be implemented in an abstract mapper class, be declared in a type (class or interface) referenced in Mapper.
During compilation, MapStruct will generate an implementation of this interface. This implementation uses plain Java method invocations for mapping between source and target objects, i.e. no reflection or similar.
MapStruct is a code generator tool that greatly simplifies the implementation of mappings between Java bean types based on a convention over configuration approach. The generated mapping code uses plain method invocations and thus is fast, type-safe, and easy to understand.
Can I use MapStruct together with Project Lombok? Yes, as of MapStruct 1.2. 0. Beta1 and Lombok 1.16.
From Mapstruct version 1.3.1.Final we can use annotation org.mapstruct.Builder#disableBuilder within: @BeanMapping, @Mapper or @MapperConfig
@Mapper(builder = @Builder(disableBuilder = true))
public interface ProjectMapper
Have a look at #mapping-with-builders and documentation
Completely disabling builders is possible via the NoOpBuilderProvider
. You need to create a org.mapstruct.ap.spi.BuilderProvider
file in the META-INF/services
directory with org.mapstruct.ap.spi.NoOpBuilderProvider
as it’s content. This will completely disable the builders.
There is a feature request to make this more granular and disable it via @BeanMapping
or on the mapper level. Have a look at mapstruct/mapstruct#1661
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