问题标签 [orika]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
577 浏览

orika - Orika - ParameterNamesNotFoundException:类缺少一个或多个@Named 注释

我在 Orika 中遇到以下异常

我有 2 个简单的 pojo,我想映射它们。

0 投票
1 回答
3261 浏览

java - Orika - 没有为源定义具体的类映射

我有一个 Class1,我想将它转换为 Class2。

Class1 和 Class2 都有一个字段:AbstractClass3 something.

AbstractClass3被声明为abstract,但它的值是 Class1&2 字段中的具体实现。

在 Class1 和 Class2 之间转换时,我得到了这个异常:

我希望 Orika 在目标类 (Class2) 中使用与源类 (Class1) 相同的实现。

实现这一目标的最佳方法是什么?

0 投票
0 回答
316 浏览

java - 简单映射配置列表 field

I'm trying to map two classes with almost the same fields: MetaInfoDTO and MetaInfo.

I've tried to configure the mapper with a default mapping. The problem is on the List<

I'm trying to map two classes with almost the same fields: MetaInfoDTO and MetaInfo.

I've tried to configure the mapper with a default mapping. The problem is on the List<Object> values field. It has the same name on the other class. So, I guess it have to be mapped correctly. See the test at the end.

And this orika configuration:

I've created a test in order to show my problem:

Class:

So, after mapping, metainfo.getValues() is empty! Is there something wrong?


How do I fetch all mongo data which is created greater than a particular date?

I read the $gt attribute has to be used. Not able to get around this. Let's say I have some mongo data like this:

That's how my start time is saved in my Mongo. If I want to get the statuses of all jobs which have the start time greater than today, How do I do it?

0 投票
1 回答
1114 浏览

java - Orika - Not working in eclipse

I having trouble getting Orika working using eclipse.... I added the maven orika dependencies (1.4.6) and I created a sample junit test

When I run the unit test, I get the following exception:

ma.glasnost.orika.MappingException: ma.glasnost.orika.impl.generator.CompilerStrategy$SourceCodeGenerationException: class PersonDTO is not accessible at ma.glasnost.orika.impl.generator.MapperGenerator.build(MapperGenerator.java:105) at ma.glasnost.orika.impl.DefaultMapperFactory.buildMapper(DefaultMapperFactory.java:1372) at ma.glasnost.orika.impl.DefaultMapperFactory.build(DefaultMapperFactory.java:1199) at ma.glasnost.orika.impl.DefaultMapperFactory.getMapperFacade(DefaultMapperFactory.java:859) at OrikaTest.test(OrikaTest.java:37) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: ma.glasnost.orika.impl.generator.CompilerStrategy$SourceCodeGenerationException: class PersonDTO is not accessible at ma.glasnost.orika.impl.generator.JavassistCompilerStrategy.assureTypeIsAccessible(JavassistCompilerStrategy.java:155) at ma.glasnost.orika.impl.generator.MapperGenerator.build(MapperGenerator.java:58) ... 27 more

Note: I see in the console eclipse printing the defined mapping. However, I get the above error when executing:

If I attempt to use the EclipseJdtCompilerStrategy, by setting the system property, I get a different exception:

java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.Compiler.(Lorg/eclipse/jdt/internal/compiler/env/INameEnvironment;Lorg/eclipse/jdt/internal/compiler/IErrorHandlingPolicy;Lorg/eclipse/jdt/internal/compiler/impl/CompilerOptions;Lorg/eclipse/jdt/internal/compiler/ICompilerRequestor;Lorg/eclipse/jdt/internal/compiler/IProblemFactory;)V at ma.glasnost.orika.impl.generator.EclipseJdtCompiler.(EclipseJdtCompiler.java:87) at ma.glasnost.orika.impl.generator.EclipseJdtCompiler.(EclipseJdtCompiler.java:77) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at java.lang.Class.newInstance(Class.java:379) at ma.glasnost.orika.impl.generator.EclipseJdtCompilerStrategy.(EclipseJdtCompilerStrategy.java:57) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at java.lang.Class.newInstance(Class.java:379) at ma.glasnost.orika.impl.UtilityResolver.resolveUtility(UtilityResolver.java:123) at ma.glasnost.orika.impl.UtilityResolver.getDefaultCompilerStrategy(UtilityResolver.java:51) at ma.glasnost.orika.impl.DefaultMapperFactory$MapperFactoryBuilder.(DefaultMapperFactory.java:310) at ma.glasnost.orika.impl.DefaultMapperFactory$Builder.(DefaultMapperFactory.java:587) at OrikaTest.test(OrikaTest.java:22) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Any help would be greatly appreciated

0 投票
2 回答
699 浏览

java - 让映射器不在特定条件下映射字段

我有一个非常特殊的用例,我手中有一个a类对象A和一个类对象bB这样a.b.equals(b)我打算使用 Orika映射a到类。C棘手的一点是,我想防止a.b被传递,而是自己插入它(a.b实际上是在我不想发生的映射期间由 JPA 获取的)。另一方面,我想a.b在所有其他用例中进行映射。

有没有一种体面的方法可以在不指定两个自定义的情况下在 Orika 中实现这种行为ClassMap

0 投票
1 回答
2422 浏览

java - Spring Boot webapp 中的 Orika ClassCastException

在我正在处理的示例 Spring Boot webapp 中,使用 Orika 将实体映射到 DTO 时,我遇到了一个奇怪的 ClassCastException。当我尝试在嵌入式 Tomcat 中对已部署的应用程序进行映射时出现异常,但我可以在 JUnit 测试上下文中很好地进行映射。这是相关的类(它们都很简单):

JPA 实体:

DTO:

休息控制器:

服务等级:

OrikaBeanMapper 类:

这是 ClassCastException 的堆栈跟踪:

我真的不知道这里发生了什么。我不明白它试图将位置转换为位置。每个实体/dto 类都会发生这种情况,而不仅仅是位置。

当我对任何方法进行单元测试时,我可以毫无问题地映射任何这些类,它运行良好并且所有字段都正确映射,所以我认为这不是 Orika 配置问题。仅当我将 webapp 部署在嵌入式 Tomcat 中并且在 rest 控制器方法中调用映射方法时才会发生异常。

这是一个简单的 Spring Boot 应用程序,这是我在其中编写的第一个 rest 端点。也许我在配置中遗漏了一些东西(我有 @EnableAutoConfiguration 所以没有那么多配置),但我猜不出是什么让 Orika 抛出这个异常。

任何关于这里可能发生的事情的想法或提示将不胜感激。

谢谢!

0 投票
2 回答
297 浏览

java - 如何发现是否为 Orika 中的两个类创建了映射器?

所以我正在编写一个远程信息处理应用程序,我们正在慢慢为 DTO 构建映射器。很快就会有超过 100 个,但现在我们有 3 个。我们想将所有消息发送到我们的映射器,但是当我们这样做并且Orika不知道它时,它会引发异常。

我需要一种.isMapperAvailable(class, class)方法,但找不到。我确实找到了一个.existsRegisteredMapper(Type, Type),但无法弄清楚它是如何工作的。有什么帮助吗?

0 投票
1 回答
542 浏览

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

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

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

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

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

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

0 投票
0 回答
170 浏览

java - Orika mapper - 如何在转换器中获取字段名称?

我在我的应用程序中使用 Orika 映射器并将一些转换器附加到字段(通过fieldMap())。是否可以在转换器中获取字段名称?

0 投票
2 回答
4384 浏览

java - 映射时向 Orika MappingContext 添加外部数据

我想将一些外部属性(不在我正在映射的对象中)添加到 MappingContext。

这是我想要完成的:

我怎样才能做到这一点?我可以动态地将数据添加到上下文中吗?还是将其他数据传递给映射器的另一种方式?