BO <=> DTO mapper in Java
Asked Answered
P

3

5

I am currently in my application maping DTOs to BO (and vice versa) manually. However, this approach is awkward and clumsy.

Is there any good mapper between these two representations?

My requirements follow:

  • Should support conversion of JPA proxies to identifiers (DTO should not link to other DTO directly). Or this functionality should be easy to implement
  • Should be annotation based, covention over configuration
  • Soft criteria: should allow mapping of multiple DTOs to one entity (and vice versa)

Thanks for any suggestions.

Papilla answered 25/1, 2013 at 14:16 Comment(1)
Have you tried this? jdto.orgVestryman
V
9

Regarding object mapping I would recommend

Also, refer to this SO answer. It has a more or less complete list of Java Object mappers: https://mcmap.net/q/115832/-any-tool-for-java-object-to-object-mapping-closed

The 3 I suggested seemed more appealing to me. I think they all fulfill the requirements you ask.

Vestryman answered 25/1, 2013 at 14:30 Comment(2)
Thanks for the links. I will check these implementations.Papilla
Just in case someone needs it. Spring 3 mapper seems to be only a preview. Documentation of jdto was not persuasive enough to try it (it seemed that the framework is not very flexible). Than I tried Dozer and Orika. Both worked fine, Dozer has also XML confix, which is a big advantage, but it is significantly slower. So I chose Orika.Papilla
K
5

Well I know this thread is a bit old, and I am pretty sure that @miguelcobain answer is great.

Personnaly, I would recommend using Orika for a runtime sytem. It is strong and uses byte code generation at runtime so mapping is handled by generated code instead of always using the Reflection API. The other listed libraries are always using complex configuration and not conventions.

The second solution and the better one, I think would be to use Selma. This short library does the job for you, but instead of handling the mapping at runtime, it generates the mapping code at compile time using an annotation processor. So compiler will raise mapping errors, this is refactoring proof and you will be able to see the generated code.

Hope you'll give it a try.

Kirshbaum answered 21/5, 2014 at 8:47 Comment(0)
T
1

I suggest you to try JMapper Framework.
It is a java bean to java bean mapper, allows you to perform the passage of data dinamically 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

Tracey answered 15/5, 2013 at 15:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.