Sitemap
Yunus Iqbal Siddique

Yunus Iqbal Siddique

Software Engineer | Simplyfying Concepts https://www.linkedin.com/in/yunusiqbalsiddique/

Data Transfer Object

2 min readJan 19, 2026
  • Widely used design pattern to transfer data between client and server. Server use DTO to send only the required amount of data to client.
  • Client ← → Controller Layer ← → Service Layer ← → Repository Layer ← → DB
  • JPA entities → we use JPA entities to map object with a relational database table. Repository layer or DAO layer uses data to store in database.
  • Disadvantages of using JPA entities to transfer data from server to client:
    - Transferring the sensitive information, which causes security issue. So in DTO we keep only the required object that client expect in response of REST api.
    - If we use DTO where we can combine the required form of data, in such a way that it needs. But this isn’t possible in JPA
  • Development Steps exp:
    1. Create UserDto class.
    2. Refactor Create User REST API to use DTO.
    3. Create UserMapper class.
    4. Refactor Get User By Id REST API to use DTO.
    5. Refactor Get All Users REST API to use DTO.
    6. Refactor Update User REST API to use DTO.
    7. Refactor Delete User REST API to use DTO.
  • With the help of model mapper library we can map JPA entity into DTO and DTO to JPA.

Get Yunus Iqbal Siddique’s stories in your inbox

Join Medium for free to get updates from this writer.

Model Mapper

  • Simple intelligent object mapping library.
  • Applications often consist of similar but different object models, where the data in two models may be similar but the structure and concerns of the models are different. Object mapping makes it easy to convert one model to another , allowing seperate models to remain segregated.
  • The goal of ModelMapper is to make object mapping easy, by automatically determining how one object model maps to another, based on conventions in the same way that a human would — while providing a simple , refactoring-safe API for handling specific use cases.
  • How it works-
    1. Add dependency of model mapper to maven dependency
    2. Configure ModelMapper class as Spring bean.
    3. Inject and use ModelMapper Spring bean in Service class.

--

--