Reputation: 121
Hi, I am trying to use mapping framework in my project, but i am not able to decide which one to choose, among these three mapping frameworks. Selma v/s MapStruct v/s Model Mapper mapping framework ?
Please help me to choose the best feature and performance oriented framework.
Upvotes: 11
Views: 28630
Reputation: 507
You can find a complete comparison between the most used frameworks to map when you click here. In this link you can find benchmark comparisons, how to use each framework etc. I decided to use MapStruct because it is easy to use and is so fast.
Upvotes: 8
Reputation: 7285
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;
}
Upvotes: 18
Reputation: 7285
I was in similar situation before while looking for solution to leverage annotation processors. I would go with either Selma or MapStruct. Kinda similar being code generators. Played with both but went with MapStruct. Similar question here in SO can help you - Java mapping: Selma vs MapStruct
Also a project in github that benchmarked object to object mapper frameworks has Selma and MapStruct in the top - https://github.com/arey/java-object-mapper-benchmark
Upvotes: 7