In MapStruct version 1.1.0.Final, this was possible....
@Mappings({
@Mapping(target = "transaction.process.details", expression = "java(MappingHelper.mapDetails(request))"),
//more mappings
})
Response requestToResponse(Request request);
It was possible, since the mapDetails
method was (by coincidence?) generated into the requestToResponse
method. That's why request
was not null.
Now, since 1.1.0.Final didn't work with Lombok, I had to upgrade to 1.2.0.CR2. With this version, the mapDetails
will be generated into a separate method where request
is not passed, so request
is null within this method now and I get a NPE with the expression. (It's a sub-sub-method of requestToResponse
now.)
Did I misuse the expression, so did it just work by coincidence, or does the new version has a bug? If no bug, how do I have to pass the request
instance to the expression properly?
You were / are misusing the expression. What you need to do is to map your target to your source parameter.
MapStruct then should create intermediary methods and use the
MappingHelper
and invoke themapDetails
method. In case you have multiple methods that map fromRequest
to whatever typedetails
are then you are going to need to used qualified mappings (see more here in the documentation).It will look something like:
And your mapping will look like: