有没有java对象到对象映射的工具?

发布于 2024-08-05 02:32:58 字数 72 浏览 5 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

葬シ愛 2024-08-12 02:32:58

那里有一些库:

  • 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)

放我走吧 2024-08-12 02:32:58

您可以尝试推土机

Dozer 是 Java Bean 到 Java Bean
递归复制数据的映射器
从一个物体到另一个物体。通常,
这些 Java Bean 会有所不同
复杂类型。

Dozer 支持简单属性
映射、复杂类型映射、
双向映射,
隐式-显式映射,以及
递归映射。这包括
映射集合属性
还需要在元素处进行映射
级别。

You could try Dozer.

Dozer is a 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.

Dozer supports simple property
mapping, complex type mapping,
bi-directional mapping,
implicit-explicit mapping, as well as
recursive mapping. This includes
mapping collection attributes that
also need mapping at the element
level.

述情 2024-08-12 02:32:58

另一种是 Orika - https://github.com/orika-mapper/orika

Orika 是一种 Java Bean 映射框架,它以递归方式将数据(以及其他功能)从一个对象复制到另一个对象。在开发多层应用程序时它非常有用。

Orika 专注于尽可能自动化,同时在需要时通过配置和扩展提供定制。

Orika 使开发人员能够:

  • 绘制复杂且深层结构的对象
  • 通过将嵌套属性映射到顶级属性来“展平”或“展开”对象,反之亦然
  • 即时创建映射器,并应用自定义来控制部分或全部映射
  • 创建转换器以完全控制对象图中任意位置的特定对象集的映射(按类型,甚至按特定属性名称)
  • 处理代理或增强对象(例如 Hibernate 或各种模拟框架的对象)
  • 通过一种配置应用双向映射
  • 映射到目标抽象类或接口的适当具体类的实例
  • 处理反向映射
  • 处理超出 JavaBean 规范的复杂约定。

Orika 使用字节代码生成以最小的开销创建快速映射器。

Another one is Orika - https://github.com/orika-mapper/orika

Orika is a Java Bean mapping framework that recursively copies (among other capabilities) data from one object to another. It can be very useful when developing multi-layered applications.

Orika focuses on automating as much as possible, while providing customization through configuration and extension where needed.

Orika enables the developer to :

  • Map complex and deeply structured objects
  • "Flatten" or "Expand" objects by mapping nested properties to top-level properties, and vice versa
  • Create mappers on-the-fly, and apply customizations to control some or all of the mapping
  • Create converters for complete control over the mapping of a specific set of objects anywhere in the object graph--by type, or even by specific property name
  • Handle proxies or enhanced objects (like those of Hibernate, or the various mock frameworks)
  • Apply bi-directional mapping with one configuration
  • Map to instances of an appropriate concrete class for a target abstract class or interface
  • Handle reverse mappings
  • Handle complex conventions beyond JavaBean specs.

Orika uses byte code generation to create fast mappers with minimal overhead.

街角卖回忆 2024-08-12 02:32:58

我的 ModelMapper 是另一个值得一试的库。 ModelMapper 的设计与其他库的不同之处在于:

  • 通过智能匹配源和目标属性来自动映射对象模型
  • 提供重构安全映射 API,使用实际代码来映射字段和方法,而不是使用字符串
  • 利用基于约定的配置来简单处理自定义查看

ModelMapper 网站以获取更多信息:

http://modelmapper.org

My ModelMapper is another library worth checking out. ModelMapper's design is different from other libraries in that it:

  • Automatically maps object models by intelligently matching source and destination properties
  • Provides a refactoring safe mapping API that uses actual code to map fields and methods rather than using strings
  • Utilizes convention based configuration for simple handling of custom scenarios

Check out the ModelMapper site for more info:

http://modelmapper.org

迷荒 2024-08-12 02:32:58

使用 Apache commons beanutils:

static void copyProperties(Object dest, Object orig)
- 将所有属性值从源 bean 复制到目标 bean
属性名称为的情况
一样。

http://commons.apache.org/proper/commons-beanutils/

Use Apache commons beanutils:

static void copyProperties(Object dest, Object orig)
-Copy property values from the origin bean to the destination bean for all
cases where the property names are the
same.

http://commons.apache.org/proper/commons-beanutils/

番薯 2024-08-12 02:32:58

还有一个 Java 映射引擎/框架 Nomin:http://nomin.sourceforge.net

There is one more Java mapping engine/framework Nomin: http://nomin.sourceforge.net.

明媚如初 2024-08-12 02:32:58

我建议您尝试 JMapper 框架

它是一个 Java bean 到 Java bean 映射器,允许您使用注释和/或 XML 动态执行数据传递。

使用 JMapper,您可以:

  • 创建和丰富目标对象
  • 将特定逻辑应用于映射
  • 自动管理 XML 文件
  • 实现 1 到 N 和 N 到 1 关系
  • 实现显式转换
  • 应用继承的配置

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:

  • Create and enrich target objects
  • Apply a specific logic to the mapping
  • Automatically manage the XML file
  • Implement the 1 to N and N to 1 relationships
  • Implement explicit conversions
  • Apply inherited configurations
对岸观火 2024-08-12 02:32:58

我很高兴添加 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.

她比我温柔 2024-08-12 02:32:58

您还可以尝试基于 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文