Skip to content

add to AbstractConverter method map to allow use another converters f…#413

Open
Merdoc97 wants to merge 3 commits into
modelmapper:masterfrom
Merdoc97:add_converter_feature
Open

add to AbstractConverter method map to allow use another converters f…#413
Merdoc97 wants to merge 3 commits into
modelmapper:masterfrom
Merdoc97:add_converter_feature

Conversation

@Merdoc97
Copy link
Copy Markdown

@Merdoc97 Merdoc97 commented Nov 6, 2018

In many use cases when use modelMapper in converter need access to MappingEngineImpl for re use already present converters.
But it not comfortable to use in converters this structure
mappingEngine.map(source, Types.deProxy(source.getClass()), null, TypeToken.<Destination>of(destinationType), null)
I think it will be useful feature when you can to reuse registered converters in any converter just using
map(Object source, Class<Destination> destinationType)

@chhsiao90
Copy link
Copy Markdown
Member

Thanks for the pull request. This pull request looks good to me. Can you use 2-space-indent instead of 4-space-indent to align with our current coding style? Thanks.

@Merdoc97
Copy link
Copy Markdown
Author

Merdoc97 commented Nov 7, 2018

Thanks for the pull request. This pull request looks good to me. Can you use 2-space-indent instead of 4-space-indent to align with our current coding style? Thanks.

changed.

@Merdoc97 Merdoc97 closed this Dec 3, 2018
@Merdoc97 Merdoc97 reopened this Aug 21, 2019
@Merdoc97
Copy link
Copy Markdown
Author

Hi recently I created pr for new feature that I think will be useful (I hope because I use it). But after solve discussion but I didn't see any respond, maybe now it will be useful ?Thats why I think this small feature will be useful ?

@chhsiao90
Copy link
Copy Markdown
Member

It's a good idea to have a method map in the AbstractConverter, but I think it will be better to remove the local variable MappingEngineImpl mappingEngine.

Any idea if we can remove the local variable? Thanks!

@Merdoc97
Copy link
Copy Markdown
Author

thanks I'm do link static.

@chhsiao90
Copy link
Copy Markdown
Member

Hi @Merdoc97 ,

Sorry for the lately reply :(
And thanks for your contribution, I'm really appreciate it.

I still think it's not a good idea to introduce mappingEngine as a local variable of AbstractConverter.
For those cases which needs the mappingEngine to convert child inside the implementation of Converter, I suggest to implement Converter directly instead of extend AbstractConverter.

class ParentConverter implements Converter<ParentEntity, ParentDTO> {

    @Override
    protected ParentDTO convert(MappingContext<ParentEntity, ParentDTO> context) {
      ParentEntity source = context.getSource();
      ParentDTO dto = new ParentDTO();
      dto.setSecondName(source.getSecondName());
      dto.setName(source.getName());
      dto.setChild(context.getMappingEngine().map(source.getChild(), ChildDTO.class));
      return dto;
    }
  }

What do you think?

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.

2 participants