A minimal demonstration of pagination with layer-to-layer DTO mapping in Java.
Extends the basic pagination sample with DTO mapping. The repository returns domain objects — Customer. The application layer converts the result into view objects — CustomerView — without rebuilding pagination metadata.
The key idea: PageResult.map() transforms the content across layers while preserving page number, size and total count unchanged.
The entire project intentionally fits in a single file — so the mechanics are visible in full, without unnecessary noise:
PaginationDtoMapping.java
│
├── Customer # Domain model — record with id and name
├── CustomerView # DTO — read model for the application layer
├── CustomerMapper # Maps Customer → CustomerView
├── PageRequest # Pagination request — page number and size
├── PageResult<T> # Pagination result — content + metadata + map()
├── CustomerRepository # Data access — returns PageResult<Customer>
├── FakeCustomerTable # In-memory data source — simulates a database table
└── PaginationDtoMapping # Entry point + demo()
PageResult.map() converts the content type without touching pagination metadata — page number, size and total are preserved automatically.
Each layer owns its transformation. The repository returns PageResult<Customer>. The application layer maps it to PageResult<CustomerView> in a single call.
CustomerMapper holds the mapping logic — domain objects and view objects stay clean with no cross-layer constructors.
PageResult[content=[CustomerView[id=1, name=Alice], CustomerView[id=2, name=Bob]], page=0, size=2, total=5]
The repository returned Customer records. The application layer received CustomerView records. Pagination metadata passed through unchanged.