-
-
Notifications
You must be signed in to change notification settings - Fork 919
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
Opt-out of using builders via a processor option #1661
Comments
Not sure how you implemented the Yes we know that the SPI is designed for multiple implementations. However, our SPI is not like that. The reason is that the SPI has methods that return names of the property for a certain accessor. If there are more, how do we know which one to use to get the name as all of them would return a certain name.
I think that we could actually do this by adding a new property to
We made it on purpose opt-out now, otherwise it won't work ootb for people. And as you noticed you can still opt out (globally) via the |
That was my approach, following the example toward the end of the reference guide, but essentially decorating the default one to account for
Fair point. It seems like that problem would exist given a single implementation which covers several naming strategies.
Great, that's along what I had envisioned. Globally via a processor option seems reasonable to me as well, though it steps on the toes of the
Fair point! I suppose of the two options, upgrade almost-blocker vs onboard blocker, almost-blocking my upgrade is better than telling others they can't use mapstruct. |
This would be resolved once we merge #1811 |
resolved.. Not sure we have it on all levels yet.. but we have it on bean mapping and mapper level. |
Processor option and mapperconfig missing |
Applying changes done in 3371058
Applying changes done in 3371058
Applying changes done in 3371058
Applying changes done in 3371058
Possibly related to #1547
I've recently been playing with 1.3 (from 1.2), testing out builder/immutable object support. I'm trying to map between 2 classes, a service layer DTO and our internal model representation. Currently, our internal model is a lombok
@Data
class, as mapstruct requires mutable objects. Ideally, we'd move to@Value
or otherwise make an immutable object, as part of the 1.3 upgrade.The DTO is generated, mutable and comes with a builder class, the builder has setters named
withAttribute
. Mapstruct 1.3 doesn't know how to map these out of the box -- it tries to use the builder then complains about not mappingwithAttribute
. I started trying out theAccessorNamingStrategy
spi. It works, but I have to support all strategies with a single class (mapstruct throws if you provide more than 1 implementation).Aside: I found this to be odd, as
ServiceLoader
s typically get multiple implementations of a service (likeProcessor
). This would allow me to write a single class to support awithAttribute
naming strategy, without having to worry about supportingsetAttribute
orattribute
still. Mapstruct could in theory support multiple by trying all implementations before being unable to find a method.While, strictly speaking, this universal naming strategy worked, I didn't feel confident that the strategy would cover all existing cases across all of our code, and future cases may be hard to integrate and be blocked.
So. Not overly confident in that, I searched for some way to simply turn off builder support. It seems this is only possible mapstruct-wide.
Not ideal, as I wanted to change our internal model to be immutable and don't want to support
withAttribute
through the spi. For my situation, I'd rather see a way to specify this method, use the builder; this method, it's just a bean. Specifying an arg as "don't use builders" would be a seamless way for me to upgrade, but mapstruct's default could be "autodetect builders" as it currently does. Overriding this config at a mapper or method level would allow me to opt-in to new features, so the new version is fully backward compatible.The text was updated successfully, but these errors were encountered: