Java中的数据库驱动模型映射

时间:2021-02-01 21:40:52

So, I have a project where I get data from a dozen different sources, some are database objects, most often the data is in different JSON formats, or often XML formats. So, I need to take this disparate data and pull it into one single clean managed object that we control.

所以,我有一个项目,我从十几个不同的源获取数据,一些是数据库对象,大多数数据采用不同的JSON格式,或者通常是XML格式。因此,我需要将这些不同的数据放入我们控制的一个干净的托管对象中。

I have seen dozens of different posts on various tools to do object to object mapping. Orika being one of them, etc. But the problem is that Orika, like many of these still need solid classes defined to do the mapping. If there is a change to the mapping, then I have to change my class, re-commit it, then do a build and deploy new code ... BTW, testing would also have to be done like any code change. So, maybe some of these tools aren't a great solution for me.

我已经在各种工具上看到了几十个不同的帖子来对象进行对象映射。 Orika是其中之一,等等。但问题是Orika,就像其中许多仍然需要定义的固定类来进行映射。如果对映射进行了更改,那么我必须更改我的类,重新提交它,然后进行构建并部署新代码......顺便说一下,测试也必须像任何代码更改一样完成。所以,也许这些工具中的一些对我来说不是一个很好的解决方案。

Then I was looking to do some sort of database-driven mapping, where I have a source, a field, and then the new field or function I would like to take it to. So, with a database-driven tool, I could modify the fields in the database, and everything would keep working as it should. I could always create a front-end to modify this tool.

然后我想做一些数据库驱动的映射,我有一个源,一个字段,然后我想要它的新字段或函数。因此,使用数据库驱动的工具,我可以修改数据库中的字段,一切都会继续工作。我总是可以创建一个前端来修改这个工具。

So, with that ... I am asking if there is any database-driven tool where I can map field to field, or fields to functions type of mapping? Drools was my first choice, but I don't know if it is my best choice? Maybe it is overkill for my needs? So, I was looking for advice on what might be the best tool to do my mapping.

所以,有了...我问是否有任何数据库驱动的工具,我可以将字段映射到字段,或字段映射到函数类型? Drools是我的第一选择,但我不知道这是否是我最好的选择?也许这对我的需求来说太过分了?所以,我一直在寻找可能是我的映射的最佳工具的建议。

Please let me know if you need any more information from me, and thanks for all the help!

如果您需要我的更多信息,请告诉我,并感谢您的帮助!

1 个解决方案

#1


0  

Actually Orika can handle dynamic Data source like that, there is even an example on how to convert from XML Element (DOM API) or even JsonObject.

实际上Orika可以像这样处理动态数据源,甚至有一个关于如何从XML Element(DOM API)甚至JsonObject转换的例子。

You can use an XML parser to convert your data into Element object, or Jackson to get JsonObject

您可以使用XML解析器将数据转换为Element对象,或使用Jackson来获取JsonObject

Then define you class map between your "Canonical" Java Class and these dynamic "Classes"

然后在“Canonical”Java类和这些动态“类”之间定义类映射

http://orika-mapper.github.io/orika-docs/advanced-mappings.html Customizing the PropertyResolverStrategy

http://orika-mapper.github.io/orika-docs/advanced-mappings.html自定义PropertyResolverStrategy

Here is an example of Orika mapping to MongoDB DBObject to Java Bean https://gist.github.com/elaatifi/ade7321a1405c61ff8a9

以下是Orika映射到MongoDB DBObject到Java Bean的示例https://gist.github.com/elaatifi/ade7321a1405c61ff8a9

However converting JSON is more straightforward than XML (the semantic of Attributes/Childs/Custom tags do not match with JavaBeans)

但是,转换JSON比XML更直接(Attributes / Childs / Custom标记的语义与JavaBeans不匹配)

#1


0  

Actually Orika can handle dynamic Data source like that, there is even an example on how to convert from XML Element (DOM API) or even JsonObject.

实际上Orika可以像这样处理动态数据源,甚至有一个关于如何从XML Element(DOM API)甚至JsonObject转换的例子。

You can use an XML parser to convert your data into Element object, or Jackson to get JsonObject

您可以使用XML解析器将数据转换为Element对象,或使用Jackson来获取JsonObject

Then define you class map between your "Canonical" Java Class and these dynamic "Classes"

然后在“Canonical”Java类和这些动态“类”之间定义类映射

http://orika-mapper.github.io/orika-docs/advanced-mappings.html Customizing the PropertyResolverStrategy

http://orika-mapper.github.io/orika-docs/advanced-mappings.html自定义PropertyResolverStrategy

Here is an example of Orika mapping to MongoDB DBObject to Java Bean https://gist.github.com/elaatifi/ade7321a1405c61ff8a9

以下是Orika映射到MongoDB DBObject到Java Bean的示例https://gist.github.com/elaatifi/ade7321a1405c61ff8a9

However converting JSON is more straightforward than XML (the semantic of Attributes/Childs/Custom tags do not match with JavaBeans)

但是,转换JSON比XML更直接(Attributes / Childs / Custom标记的语义与JavaBeans不匹配)