malejpavouk
malejpavouk

Reputation: 4445

BO <=> DTO mapper in Java

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:

Thanks for any suggestions.

Upvotes: 5

Views: 9006

Answers (3)

miguelcobain
miguelcobain

Reputation: 4754

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://stackoverflow.com/a/1432956/1137735

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

Upvotes: 9

slemesle
slemesle

Reputation: 1129

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.

Upvotes: 5

Alessandro
Alessandro

Reputation: 282

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

Upvotes: 1

Related Questions