Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java mapping: Selma vs MapStruct [closed]

Currently there are two main popular Java Object to Object mapping frameworks that supersede Dozer (http://dozer.sourceforge.net/documentation/mappings.html), they are:

  1. Selma - http://www.selma-java.org/
  2. MapStruct - http://mapstruct.org/

With the exception of this page (http://vytas.io/blog/java/java-object-to-object-mapping-which-framework-to-choose-part-2/) I haven't been able to find much online regarding which framework is better than the other, or under what circumstances they are better. Wondering if anyone you can shed some light on this. In terms of functionality based on the documents, they seem to be doing the same thing.

like image 722
JackDev Avatar asked Jan 14 '16 10:01

JackDev


People also ask

Is it good to use MapStruct?

Excellent performance, as no reflection or byte code generation at runtime is needed; the generated code contains plain method invocations, just as if the mapper was hand-written. No runtime dependencies, making MapStruct a great solution for Android applications.

Is MapStruct slow?

Throughput. In throughput mode, MapStruct was the fastest of the tested frameworks, with JMapper a close second.

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.

Is MapStruct a framework?

In contrast to other mapping frameworks MapStruct generates bean mappings at compile-time which ensures a high performance, allows for fast developer feedback and thorough error checking.


1 Answers

(Original author of MapStruct here, so naturally I am biased)

Indeed, both projects are based on the same general idea of generating mapping code at compile time; I recommend you MapStruct for the following reasons:

  • Proven and stable codebase: MapStruct is the older of the two, coming up with the idea of mapping generation originally. It has been enhanced and polished over quite a long time, based on real-world feedback from usage in many different projects; We released the stable 1.0 Final last year
  • Larger developer and user community as per the number of committers (MapStruct, Selma) and user questions (MapStruct, Selma)
  • Feature-rich (Some things supported in MapStruct I didn't find (to the same extend) in the Selma docs):
    • Many built-in type conversions, including advanced support for JAXB types such as JAXBElement
    • Support for default values and constants
    • Mapping customizations through inline expressions
    • Sharing configurations across mappers
    • Nicely integrates with CDI and JSR 330 (in addition to Spring)
  • Eclipse plug-in avaible: Still work in progress, but its quickfixes and auto-completions are already very helpful when designing mapper interfaces
  • IntelliJ plug-in: helps when editing mapper interfaces via auto-completion, go to referenced properties, refactoring support etc.
like image 99
Gunnar Avatar answered Sep 22 '22 03:09

Gunnar