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.
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.
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.
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.
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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With