Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selma v/s MapStruct v/s Model Mapper which one to chose as java mapping framework.?

Tags:

mapping

Hi, I am trying to use mapping framework in my project, but i am not able to decide which one to chose, among these there mapping framework. Selma v/s MapStruct v/s Model Mapper mapping framework ?

Please help me to chose the best feature and performance oriented framework.

like image 290
user3747449_Santhosh Avatar asked Dec 05 '17 13:12

user3747449_Santhosh


People also ask

What is Mapper map in Java?

Overview. Dozer is a Java Bean to Java Bean mapper that recursively copies data from one object to another, attribute by attribute. The library not only supports mapping between attribute names of Java Beans, but also automatically converts between types – if they're different.

Why Mapper is used in Java?

ObjectMapper class ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Plain Old Java Objects), or to and from a general-purpose JSON Tree Model (JsonNode), as well as related functionality for performing conversions.

What is MapStruct used for?

MapStruct is a code generator tool that greatly simplifies the implementation of mappings between Java bean types based on a convention over configuration approach. The generated mapping code uses plain method invocations and thus is fast, type-safe, and easy to understand.

What is Java bean mapping?

JMapper is the mapping framework that aims to provide an easy-to-use, high-performance mapping between Java Beans. The framework aims to apply the DRY principle using Annotations and relational mapping. The framework allows for different ways of configuration: annotation-based, XML or API-based.


1 Answers

In light of the Java 8 Stream APIs and with lombok annotation processor library, I am no longer using this mapping frameworks. I create my own mappers by implementing the Converter interface of the spring framework (package org.springframework.core.convert.converter.Converter)

    @Component
    public class ProductToProductDTO implements Converter<Product, ProductDTO> {
        @Override public ProductDTO convert( Product source ) {
            ProductDTO to = ProductDTO.builder()
                    .name( source.getName())
                    .description( source.getDescription() )
                    .tags(source.getTags().stream().map(t -> t.getTag().getLabel()).collect( Collectors.toList()))
                            .build();
            return to;
        }
    }

    @Builder //lombok annotation to create Builder class
    @Data //lombok annotation to create getters & setters
    @AllArgsConstructor //required for @Builder
    public class ProductDTO  {
        private String name;
        private String description;
        private List<String> tags;
    }
like image 110
alltej Avatar answered Sep 28 '22 02:09

alltej