Orika: customize MappingFacade

273 views Asked by At

2 classes:User and UserDto. Its have fields, which differ from the the point of in User fields set with underlining (for example: "first_name"), then in UserDto - in CamelCase ("firstName"). I have a task to map fields from User to UserDto, using MapperFacade:

  MapperFacade mapper = mapperFactory.getMapperFacade();
  UserDto userDto = mapper.map(user, UserDto.class);

But this does not work - as I understand the reason is difference of styles. In UserDto keys for mapping with CamelCase, and in User - without CamelCase.

Is there any way to customize the mapping so that underlining or Camel case will be ignored?

I considered Orica-Converter, but I cant understand, how It can help me in solving of this problem.

1

There are 1 answers

0
Jelly On

The problem is solved by applying different mapper - ModelMapper. The solution have founded during 0,5 hours and is as follows:

 ModelMapper mapper = new ModelMapper();
    mapper.getConfiguration()
            .setSourceNameTokenizer(NameTokenizers.UNDERSCORE)
            .setSourceNameTokenizer(NameTokenizers.CAMEL_CASE);

That's all! ))