Reputation: 29477
I am tyring to understand, fundamentally, what problem(s) the Dozer Mapping framework solves.
According to their tutorials, Dozer:
Dozer is a Java Bean to Java Bean mapper that recursively copies data from one object to another. Typically, these Java Beans will be of different complex types.
A code example from their docs:
Mapper mapper = new DozerBeanMapper();
DestinationObject destObject = new DestinationObject();
mapper.map(sourceObject, destObject);
But how is this any different than a HashMap
? What benefit does a Dozer map give us over a stadard JRE Map
implementation? I can accomplish the same thing as above with the JRE:
Map<SourceObject, DestinationObject> mapper = new ConcurrentHashMap<SourceObject, DestinationObject>();
mapper.map(new SourceObject(), new DestinationObject());
What am I missing here?
Upvotes: 0
Views: 606
Reputation: 3500
Imagine this situation.. You have an entity class, which has many fields, and want to pass this class to another app. But, you don't want to pass all of the field values, beacause you only want to share certain fields (maybe you have fields that shoud stay private).
So, most of the times, we deal with this by having two class implementations.. the entity, and the "portable" version of the entity, which doesn't have the fields we don't want to share, etc, etc. This is known as a DTO (data transfer object).
Without dozer, we have to create the portable version, and set all of it's fields from the entity..
PortablePerson portPerson = new PortablePerson();
portPerson.setId(person.getId());
portPerson.setName(person.getName());
...
...
Dozer does all this tedious work for us.. As long as the fields are called the same between real class and portable class, dozer mappings works without any configuration.
Hope it helps!
Upvotes: 3