English 中文(简体)
Alternative to dozer for bean mapping? [closed]
原标题:

I am trying to figure out an easy way to map DTOs to entities without the boiler-plate code. While I was thinking of using dozer it appears to require a lot of xml configuration. Has anybody seen a dozer alternative that uses a DSL to configure the bean mapping in pure Java?

Ideally I am hoping to find a bean mapper that is inspired by the way Guice does things.

最佳回答

I was looking for alternatives as well.

Here is a very good coverage of different options.

问题回答

Look at 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.

From my point of view, the configuration or java code to map some special properties are always needed.

Here I want to take a DO and DTO for example

DO:{
    id: "id",
    name:"name",
    doName1: "doName1",
    nestedObj: {
        id: "nestedObjId",
        name: "nestedObjName"
    }
}

DTO{
    id: "",
    name: "",
    name1: ""   // for mapping doName1 in DO.
    nestedId: "", //for DT.nestObj.id
    nestedName: "", //for DT.nestObj.name
}

For Dozer or Orika they both can automatically match id and name property between DO and DTO without any configuration or java code because they are with the same property names and types. But if you want to DO.doName1 <----> DTO.name1 or DO.nestedObj.id <--->DTO.nestedId you need to make some configuration (via xml or java) to tell the mapping tool you are intend to do that. I think for your use case, Dozer, Orika and ModelMapper are all OK. But for me I am switching my project from dozer to Orika for performance purpose. Although Orika is not so mature as dozer, not so intelligence and requires me to do a lot additional job to maintain my customized mapping configurations. If your project not too care about performance I will recommend you dozer, it’s so easy to use and support so many advanced features. Otherwise if you are purchasing high performance, i suggest you orika.





相关问题
NHibernate fetching/automapper issues

Okay so I have an issue at the moment which is either down to AutoMapper, my NHibernate query or Domain/DTO design. The problem I have is that when i do a fetch, for example ObjectA contains a list ...

Has Chrome improperly implemented the dataTransfer object?

When I do this in dragstart event: e.dataTransfer.setData( text/plain , text ); e.dataTransfer.setData( text/html , html ); e.dataTransfer.setData( application/x-bookmark , bookmark ); and this ...

Alternative to dozer for bean mapping? [closed]

I am trying to figure out an easy way to map DTOs to entities without the boiler-plate code. While I was thinking of using dozer it appears to require a lot of xml configuration. Has anybody seen a ...

Design issues with DTO s etc

I am designing a web application in c# that mostly talks with the database. I have created a DTO for each table in the database. Now for each Table there is a custom table repository class that does ...

Repository + NHibernate + DTO

I have an application with a repository layer (and a nhibernate implementation), service (bussiness) layer, and an asp.net mvc in the web layer. Because I also need to create a small silverlight ...

热门标签