Mapping Objects of Data Sources
To fill DTO objects with data, you first need to get the data from somewhere, e.g. from a database or a webservice.
Sometimes it is desirable to cache the loaded data in order to be able to use it for subsequent database or webservice calls.
The AbstractDto
class comes with a special field originalData
that is meant to be used for such caching:
public abstract class AbstractDto implements Serializable {
...
private Object originalData;
...
public Object getOriginalData() {
return originalData;
}
public void setOriginalData(Object originalData) {
this.originalData = originalData;
}
...
}
Apart from serving for caching, the originalData
has another advantage.
It maps a DTO object to an object that got retrieved from a database or webservice.
So you needn’t write additional code to implement such a mapping.
Note
Use the originalData
functionality with care.
If you use objects that use a big amount of memory and you want to store a DTO object for a long time, e.g. for the lifetime of a user session, you might be better off not using this functionality since it unnecessarily consumes memory.