有没有java对象到对象映射的工具?
我正在尝试使用 java 将 DO 转换为 DTO,并在开始编写自己的工具之前寻找自动化工具。我只是想知道是否有任何免费工具可用。
I am trying to convert DO to DTO using java and looking for automated tool before start writing my own. I just wanted to know if there any free tool available for the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
那里有一些库:
Commons-BeanUtils: ConvertUtils ->用于将字符串标量值转换为指定类的对象、将字符串数组转换为指定类的数组的实用方法。
Commons-Lang:ArrayUtils ->对数组、原始数组(如 int[])和原始包装数组(如 Integer[])的操作。
Spring框架:Spring对PropertyEditors有很好的支持,它也可以用来将对象转换为字符串或从字符串转换.
Dozer:Dozer 是一个功能强大但简单的 Java Bean 到 Java Bean 映射器,可递归复制数据从一个物体到另一个物体。通常,这些 Java Bean 具有不同的复杂类型。
ModelMapper:ModelMapper是一个智能对象映射框架,可以自动将对象相互映射。它使用基于约定的方法来映射对象,同时提供简单的重构安全 API 来处理特定用例。
MapStruct:MapStruct 是 bean 映射的编译时代码生成器,速度快(不使用反射或类似),运行时无依赖且类型安全的映射代码。
Orika:Orika 使用字节代码生成以最小的开销创建快速映射器。
Selma:用于映射的编译时代码生成器
JMapper:使用注释、XML 或 API 生成 Bean 映射器(似乎已死,上次更新于 2 年前)Smooks:Smooks JavaBean Cartridge 允许您从消息数据创建并填充 Java 对象(即将数据绑定到)(由评论中的 superfilin 建议)。(不再积极开发)Commons-Convert:Commons -Convert 旨在提供一个专用于将一种类型的对象转换为另一种类型的任务的单一库。第一阶段将重点关注对象到字符串和字符串到对象的转换。 (似乎已死,上次更新 2010 年)Transmorph:Transmorph 是一个免费的java库,用于将一种类型的Java对象转换为另一种类型的对象(具有另一个签名,可能是参数化的)。(似乎已死,最后更新2013年)EZMorph:EZMorph 是一个简单的 java 库,用于将一个对象转换为另一个对象。它支持基元和对象的转换、多维数组以及使用 DynaBeans 的转换(似乎已死,最后更新于 2008 年)Morph:Morph 是一个 Java 框架,可简化应用程序的内部互操作性。当信息流经应用程序时,它会经历多次转换。 Morph 提供了一种标准方法来实现这些转换。(似乎已死,上次更新 2008 年)洛伦兹:洛伦兹是一个通用的对象到对象的转换框架。它提供了一个简单的API来将一种类型的Java对象转换为另一种类型的对象。(似乎已经死了)OTOM:使用 OTOM,您可以将任何数据从任何对象复制到任何其他对象。可能性是无限的。欢迎来到“秋天”。(似乎死了)There are some libraries around there:
Commons-BeanUtils: ConvertUtils -> Utility methods for converting String scalar values to objects of the specified Class, String arrays to arrays of the specified Class.
Commons-Lang: ArrayUtils -> Operations on arrays, primitive arrays (like int[]) and primitive wrapper arrays (like Integer[]).
Spring framework: Spring has an excellent support for PropertyEditors, that can also be used to transform Objects to/from Strings.
Dozer: Dozer is a powerful, yet simple Java Bean to Java Bean mapper that recursively copies data from one object to another. Typically, these Java Beans will be of different complex types.
ModelMapper: ModelMapper is an intelligent object mapping framework that automatically maps objects to each other. It uses a convention based approach to map objects while providing a simple refactoring safe API for handling specific use cases.
MapStruct: MapStruct is a compile-time code generator for bean mappings, resulting in fast (no usage of reflection or similar), dependency-less and type-safe mapping code at runtime.
Orika: Orika uses byte code generation to create fast mappers with minimal overhead.
Selma: Compile-time code-generator for mappings
JMapper: Bean mapper generation using Annotation, XML or API(seems dead, last updated 2 years ago)Smooks: The Smooks JavaBean Cartridge allows you to create and populate Java objects from your message data (i.e. bind data to) (suggested by superfilin in comments).(No longer under active development)Commons-Convert: Commons-Convert aims to provide a single library dedicated to the task of converting an object of one type to another. The first stage will focus on Object to String and String to Object conversions. (seems dead, last update 2010)Transmorph: Transmorph is a free java library used to convert a Java object of one type into an object of another type (with another signature, possibly parameterized).(seems dead, last update 2013)EZMorph: EZMorph is simple java library for transforming an Object to another Object. It supports transformations for primitives and Objects, for multidimensional arrays and transformations with DynaBeans(seems dead, last updated 2008)Morph: Morph is a Java framework that eases the internal interoperability of an application. As information flows through an application, it undergoes multiple transformations. Morph provides a standard way to implement these transformations.(seems dead, last update 2008)Lorentz: Lorentz is a generic object-to-object conversion framework. It provides a simple API to convert a Java objects of one type into an object of another type.(seems dead)OTOM: With OTOM, you can copy any data from any object to any other object. The possibilities are endless. Welcome to "Autumn".(seems dead)您可以尝试推土机。
You could try Dozer.
另一种是 Orika - https://github.com/orika-mapper/orika
Another one is Orika - https://github.com/orika-mapper/orika
我的 ModelMapper 是另一个值得一试的库。 ModelMapper 的设计与其他库的不同之处在于:
ModelMapper 网站以获取更多信息:
http://modelmapper.org
My ModelMapper is another library worth checking out. ModelMapper's design is different from other libraries in that it:
Check out the ModelMapper site for more info:
http://modelmapper.org
使用 Apache commons beanutils:
http://commons.apache.org/proper/commons-beanutils/
Use Apache commons beanutils:
http://commons.apache.org/proper/commons-beanutils/
还有一个 Java 映射引擎/框架 Nomin:http://nomin.sourceforge.net。
There is one more Java mapping engine/framework Nomin: http://nomin.sourceforge.net.
我建议您尝试 JMapper 框架。
它是一个 Java bean 到 Java bean 映射器,允许您使用注释和/或 XML 动态执行数据传递。
使用 JMapper,您可以:
I suggest you try JMapper Framework.
It is a Java bean to Java bean mapper, allows you to perform the passage of data dynamically with annotations and / or XML.
With JMapper you can:
我很高兴添加 Moo 作为一个选项,尽管显然我对它有偏见:
http://geoffreywiseman.github.com/Moo/
对于简单的情况来说非常好用,合理能够处理更复杂的情况,尽管我仍然可以想象在某些领域增强它以实现更复杂的情况。
I'm happy to add Moo as an option, although clearly I'm biased towards it:
http://geoffreywiseman.github.com/Moo/
It's very easy to use for simple cases, reasonable capable for more complex cases, although there are still some areas where I can imagine enhancing it for even further complexities.
您还可以尝试基于 Dozer 的映射框架,但使用 Excel 映射声明。他们有一些工具和其他很酷的功能。
检查 http://openl-tablets.sf.net/mapper
You can also try mapping framework based on Dozer, but with Excel mapping declaration. They've got some tools and additional cool features.
Check at http://openl-tablets.sf.net/mapper