Java映射:Selma与MapStruct [英] Java mapping: Selma vs MapStruct

查看:1031
本文介绍了Java映射:Selma与MapStruct的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前有两个主要的Java Object to Object映射框架取代了Dozer( http:// dozer.sourceforge.net/documentation/mappings.html ),它们是:

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/

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

除了这个页面( http://vytas.io/blog/java/java-object-to-object-mapping-which-framework-to-choose-part-2/ )我还没能在网上找到关于哪个框架比另一个更好的框架,或者在什么情况下它们更好。想知道是否有人可以对此有所了解。在基于文档的功能方面,他们似乎做了同样的事情。

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.

推荐答案

(塞尔玛的原作者如此轻微不同的观点)

(Original author of Selma so slight different point of view)

Selma和MapStruct在完成同样的工作时会有一些差异。首先看来,Selma生成的代码比MapStruct快一点( http://javaetmoi.com/wp-content/uploads/2015/09/2015-09-mapping-objet-objet2.png )。 0.13版本号并未真正反映代码的成熟度。塞尔玛稳定且稳健,在生产中使用2年。

Selma and MapStruct does the same job with some differences. First it appears that Selma generated code is just a bit faster than MapStruct (http://javaetmoi.com/wp-content/uploads/2015/09/2015-09-mapping-objet-objet2.png). The 0.13 release number does not really reflects the maturity of code Selma is stable and robust it is in use in production for 2 years.

塞尔玛背后的主要理念是禁止魔术转换,只是自动化所有映射,没有任何副作用。当映射看起来太复杂时,开发人员应该使用自定义映射或拦截器自己处理它。

The main idea behind Selma is to prohibit magic conversion and just automate all mappings without any side effects. When mapping appears to be too complex, the developer should handle it by himself using custom mappings or interceptor.

Selma的占用空间尽可能小,我们只依赖于JavaWriter和JDK。

The footprint of Selma is built to be as small as possible we only depend on a JavaWriter and the JDK.

Selma尝试仅使用静态编译生成的代码而不在运行时进行任何反射或在字符串字段中编写伪代码。

Selma tries to only use static compiled generated code without any reflection at runtime or pseudo-code written in string fields.

您可以使用合成来构建映射器链在单个映射器中,您可以使用可以基于每个方法覆盖的全局配置。

You can use composition to build a chain of mappers and inside a single mapper you can have global configuration that can be overwritten on a per method basis.

编译器消息旨在为开发人员提供早期反馈,解决问题的技巧和学习API。

Compiler messages are built to give developer early feedback, tips to solve the issue and learn the API.

最后,确保MapStruct功能更丰富,但Selma为开发人员提供了复杂映射所需的所有工具,并负责编写业务逻辑。从用户的角度来看,您还可以找到比其他API更好的2个API中的一个,因此最好的办法是尝试两者并选择您感觉更舒服的API。这不会是耗时的。

At the end for sure MapStruct is more feature rich but Selma gives developer all the tools needed for complex mapping with the responsibility of writing the business logic. You could also find one of the 2 APIs nicer than the other from a user perspective so best thing to do is to try both and choose the one you feel more comfortable with. It won't be time consuming.

这篇关于Java映射:Selma与MapStruct的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆