Skip to content
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

Support merging with mapper annotation #11330

Open
wants to merge 2 commits into
base: 4.8.x
Choose a base branch
from

Conversation

andriy-dmytruk
Copy link
Contributor

Support merging with @Mapper annotation.

For example, the following method definitions are supported:

@Singleton
@Mapper
abstract class TestMerge {

    @Mapper
    abstract Skeleton merge(SkeletonPartA a, SkeletonPartB b, SkeletonPartC c);

    @Mapper.Mapping(from = "a.halloweenDescription", to = "description")
    @Mapper.Mapping(from = "#{a.deadAge + a.aliveAge}", to = "age")
    abstract Skeleton merge(CustomPart a, SkeletonPartB b, SkeletonPartC c);

    @Mapper
    abstract Skeleton update(Skeleton skeleton, Map<String, Object> values);

    @Mapper.Mapping(from = "values.halloweenDescription", to = "description")
    @Mapper.Mapping(from = "#{skeleton.get('deadAge')}", to = "age")
    abstract Skeleton merge(Map<String, Object> skeleton, Map<String, Object> values);

    @Mapper(mergeStrategy = "EXPLICITLY_SET")
    @Mapper.Mapping(from = "updater.halloweenDescription", to = "description")
    abstract Skeleton updateExplicitlySet(Skeleton current, SkeletonUpdater updater)

    @Mapper(mergeStrategy = Mapper.MERGE_STRATEGY_ALWAYS_OVERRIDE)
    @Mapper.Mapping(from = "updater.halloweenDescription", to = "description")
    abstract Skeleton updateAlwaysOverride(Skeleton current, SkeletonUpdater updater)

    @Mapper(mergeStrategy = Mapper.MERGE_STRATEGY_NOT_NULL_OVERRIDE)
    @Mapper.Mapping(from = "updater.halloweenDescription", to = "description")
    abstract Skeleton updateNotNullOverride(Skeleton current, SkeletonUpdater updater)
}

Copy link

sonarcloud bot commented Nov 8, 2024

Copy link
Contributor

@graemerocher graemerocher left a comment

Choose a reason for hiding this comment

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

Looks good, can you update the docs here as well https://docs.micronaut.io/4.6.5/guide/#beanMappers

int i = builder.indexOf(key);
if (!isDefault && mapStrategy.customMappers().containsKey(key)) {
return;
private class DefaultMapInvocation implements MapInvocation {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be a record?

@graemerocher
Copy link
Contributor

not sure if this can make it in 4.7 or not. @sdelamo will know

@sdelamo sdelamo changed the base branch from 4.7.x to 4.8.x November 11, 2024 18:07
@sdelamo
Copy link
Contributor

sdelamo commented Nov 11, 2024

not sure if this can make it in 4.7 or not. @sdelamo will know

I will prefer 4.8. I want to deliver 4.7 as soon as possible.

@andriy-dmytruk
Copy link
Contributor Author

I will prefer 4.8. I want to deliver 4.7 as soon as possible.

4.8 is fine with me. There is no need to rush this change

@graemerocher
Copy link
Contributor

@andriy-dmytruk can you retarget 4.8.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants