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

External mapper injection #10

Closed
sonytricoire opened this issue Nov 28, 2013 · 2 comments
Closed

External mapper injection #10

sonytricoire opened this issue Nov 28, 2013 · 2 comments

Comments

@sonytricoire
Copy link

I need to inject an existing mapper into another mapper to avoid duplication mapping rules.

For example, if want to inject an existing mapper to manage the ConfigProfile class mapping, I expect something like

mapper1 = new Mapper()
                .biMapping(ConfigProfile.class, ConfigProfileDTO.class);
...
mapper = new Mapper()
                .biMapping(Device.class, DeviceDTO.class)
                .injectMapper(mapper1, ConfigProfile.class);

@JoanZapata
Copy link
Owner

What I would do to avoid duplication is to have only one Mapper instance for all the mappings, as Mapper is thread-safe and there shouldn't be conflicting cases.

In your .injectMapper(mapper1, ConfigProfile.class), what is ConfigProfile.class for ?

If that means "I want the ConfigProfile class to be mapped only by mapper1, then what about that :

Mapper mapper = new Mapper()
    .custom(new CustomMapper<ConfigProfile, ConfigProfileDTO >() {
        @Override
        public ConfigProfileDTO customMapping(ConfigProfile source) {
            return mapper1.map(source); // or anything else
        }
    };
});

I think it's better because it allows for other mapping libraries to be easily integrated in simple-mapper.

Would it be ok for you ?

@sonytricoire
Copy link
Author

Yep seems right !

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

No branches or pull requests

2 participants