Book Image

Building a RESTful Web Service with Spring

By : Ludovic Dewailly
Book Image

Building a RESTful Web Service with Spring

By: Ludovic Dewailly

Overview of this book

Table of Contents (17 chapters)
Building a RESTful Web Service with Spring
About the Author
About the Reviewers

The Data-Transfer-Object design pattern

A data transfer object is a simple wrapper around properties, which is passed between layers of an application. This pattern offers a good abstraction level between how the data is stored and managed internally and how it is represented.

Such objects typically define no business logic, and simply fulfill the role of a data container. In the context of our sample property management web service, we declare, for example, a DTO class for Rooms. The following code snippet illustrates this DTO class:

public class RoomDTO implements Serializable {

    private static final long serialVersionUID = 2682046985632747474L;

    private long id;
    private String name;
    private long roomCategoryId;
    private String description;

    public RoomDTO(Room room) { = room.getId(); = room.getName();
        this.roomCategoryId = room.getRoomCategory().getId();
        this.description = room.getDescription();

    public long...