Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need a bean to bean mapper like dozer in a web application

In simple terms, why do we need 'a bean to bean mapping service' (like Dozer) in a web-application.

Suppose I'm working on a web-service.

  1. I'm receiving an XML in request.
  2. I fetch the the values from XML elements.
  3. Perform the required operation on the fetched values.
  4. Prepare the response XML.
  5. Send the response XML as response

Why should I add one more steps of mapping XML elements to own custom elements.

I'm not able to convince myself, probably because I'm not able to think of a better situation/reason.

Please suggest, with example if possible.

like image 429
reiley Avatar asked Aug 29 '14 07:08

reiley


People also ask

What is Dozer Bean mapper?

Dozer is a Java Bean to Java Bean mapper that recursively copies data from one object to another, attribute by attribute. The library not only supports mapping between attribute names of Java Beans, but also automatically converts between types – if they're different.

Why do we use Mapper in Java?

ObjectMapper class ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Plain Old Java Objects), or to and from a general-purpose JSON Tree Model (JsonNode), as well as related functionality for performing conversions.

What is Java Bean mapping?

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. Orika focuses on automating as much as possible, while providing customization through configuration and extension where needed.

What is the use of mapper class?

It acts as a mapper between two objects and transforms one object type into another. It converts the input object of one type to the output object of another type until the latter type follows or maintains the conventions of AutoMapper.


1 Answers

It helps to reduce coupling between the presentation (i.e. the XML schema) and the business logic. For example in case of schema changes you don't have to touch the business logic, just the mapping between the objects.

In simple cases it might not be worth the additional complexity. But if the objects are used extensively in the business logic component you should consider it.

like image 192
Henry Avatar answered Nov 01 '22 14:11

Henry