Skip to content

Conversation

@venkatesh2090
Copy link
Contributor

@venkatesh2090 venkatesh2090 commented Jul 12, 2023

Add support for specifying unmappedSourcePolicy similar to unmappedTargetPolicy on BeanMapping.

Fixes #3309

Copy link
Member

@filiphr filiphr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this @venkatesh2090.

Have a look at my comments. In addition to that, can you please add tests with different policies and also a combination of policy on @Mapper and @BeanMapping to show that it is being picked up properly

Copy link
Member

@filiphr filiphr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. I've added one last comment and we'll merge once that is done and the build is green

/**
* How unmapped properties of the source type of a mapping should be reported.
* If no policy is configured, the policy given via {@link MapperConfig#unmappedSourcePolicy()} or
* {@link Mapper#unmappedSourcePolicy()} will be applied, using {@link ReportingPolicy#WARN} by default.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* {@link Mapper#unmappedSourcePolicy()} will be applied, using {@link ReportingPolicy#WARN} by default.
* {@link Mapper#unmappedSourcePolicy()} will be applied, using {@link ReportingPolicy#IGNORE} by default.

@venkatesh2090
Copy link
Contributor Author

I was refactoring the tests and writing more which broke more stuff. I'll fix it and push it once it's done. FYI here's the error I get during the tests.

ERROR BeanMappingSourcePolicyMapper.java:20 'nullValueMappingStrategy', 'nullValuePropertyMappingStrategy', 'resultType' and 'qualifiedBy' are undefined in @BeanMapping, define at least one of them.

It might take a bit more time. My bad.

@venkatesh2090
Copy link
Contributor Author

I did manage to fix it, but I have one concern.

This error message in Message looks outdated. It is being used in BeanMappingOptions.isConsistent where it checks for more values than the error message points out. The message is inconsistent I think.

Copy link
Member

@filiphr filiphr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @venkatesh2090, one last comment for the integration tests to pass and we are done. You are right, the error message in the @BeanMapping is inconsistent. We can change this in a different PR. The message doesn't need to enumarate all options, we can just say @BeanMapping must have at least one option defined

import org.mapstruct.ReportingPolicy;

@Mapper(unmappedSourcePolicy = ReportingPolicy.WARN)
public interface BeanMappingSourcePolicyErrorMapper {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should contain ErroneousMapper, e.g. BeanMappingSourcePolicyErroneousMapper. Doing it like this will make sure that the integration tests will ignore this mapper

@filiphr filiphr merged commit 279ab22 into mapstruct:main Aug 1, 2023
@filiphr
Copy link
Member

filiphr commented Aug 1, 2023

Thanks @venkatesh2090, this has been integrated into main

@venkatesh2090 venkatesh2090 deleted the issue-3309 branch August 1, 2023 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add BeanMapping#unmappedSourcePolicy

2 participants