-
Notifications
You must be signed in to change notification settings - Fork 509
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
mapstruct-mapper-repo example bug #79
Comments
@everettwolf I don't think I understand what you are trying to do? Can you provide a test case with what is wrong? The Line 29 in 974fb1d
which the |
Hey @filiphr thanks for the reply! For the latter, my use case is this (and this was what I was trying to solve when I stumbled over the above): and Target could look like this: After mapping the source to the target, I would want Target to look like this: IOW, any field where the source property is null, the equivalent target property is NOT updated. I saw a few people asking about this, and a response in the form of this PR: However, I can't get it to work with the latest version, and the examples provided in this repo don't appear to cover it. It's no big deal; I was hoping to drop mapstruct into a project I'm working on to solve the use case I mentioned, but I ended up just creating my own mapping annotations, and it works fine. Thanks!! |
Just took a quick look (at home w/ the kids due to Covid, so it's a bit tough ;o)) For mapstruct-mapper-repo, this is what the generated Implementation of the CarMapper looks like:
} Note that the mapping method includes the seatCount conversion, but the update method does not. If this is by design, can you explain why? Thanks! |
Hmm, thought I was on to something: numberOfSeats and seatCount (in Car & CarDto) were a primitive (int) so the null checking annotation wouldn't be able to do anything with that, so thinking the generator realizes that and doesn't add primitives to the update method in this scenario. However, I changed both to Integer and regenerated (by the way, have to delete the target directory to get that kind of change picked up on a mvn clean compile), and still the same issue. I can go in and modify the generated output to do what I want, but that wouldn't be very elegant. I'll just stop and let you respond, thus far; I'm probably missing something. Not sure you'd want to embark on an Autoboxing/Unboxing rabbit hole to work around the "check for null on source" issue. |
in testMapObjectToObject add:
carDto.setSetCount(7);
and
Assert.assertEquals(5, carDto.getSeatCount());
test will fail
Also, despite the annotation
@Mapper(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
on CarMapper:
in testMapObjectToObject
change
Car car = new Car("Morris", 5, CarType.SPORTS);
to
Car car = new Car("Morris", 5, null);
and add
carDto.setType("anything");
and
Assert.assertEquals("anything", carDto.getType());
test will fail
For the latter, I tried to make sense of your recent change of "don't overwrite target if source is null" pull request, but there was so much discussion on what the annotation should be, I couldn't easily figure out the end result. ;o)
I also can't find a test case in this git repo that covers it. Can you point me to it, if there is one?
Thanks!
The text was updated successfully, but these errors were encountered: