Questions tagged [dto]
DTO is an acronym for Data Transfer Object, a design pattern used in data transfer.
2,140
questions
681
votes
9
answers
570k
views
Difference between DTO, VO, POJO, JavaBeans?
Have seen some similar questions:
What is the difference between a JavaBean and a POJO?
What is the Difference Between POJO (Plain Old Java Object) and DTO (Data Transfer Object)?
Can you also ...
437
votes
10
answers
157k
views
Plain Old CLR Object vs Data Transfer Object
POCO = Plain Old CLR (or better: Class) Object
DTO = Data Transfer Object
In this post there is a difference, but frankly most of the blogs I read describe POCO in the way DTO is defined: DTOs are ...
417
votes
12
answers
392k
views
What is a Data Transfer Object (DTO)?
In MVC are the model classes DTO? If not, what are the differences and do we need both?
250
votes
9
answers
185k
views
any tool for java object to object mapping? [closed]
I am trying to convert DO to DTO using java and looking for automated tool before start writing my own. I just wanted to know if there any free tool available for the same.
211
votes
4
answers
127k
views
REST API - DTOs or not? [closed]
I am currently creating a REST-API for a project and have been reading article upon article about best practices. Many seem to be against DTOs and simply just expose the domain model, while others ...
156
votes
12
answers
80k
views
Why are data transfer objects (DTOs) an anti-pattern?
I've recently overheard people saying that data transfer objects (DTOs) are an anti-pattern.
Why? What are the alternatives?
133
votes
9
answers
63k
views
DTO = ViewModel?
I'm using NHibernate to persist my domain objects.
To keep things simple I'm using an ASP.NET MVC project as both my presentation layer, and my service layer.
I want to return my domain objects in ...
115
votes
7
answers
72k
views
What is the difference between an MVC Model object, a domain object and a DTO
What is the difference between a MVC Model object, a domain object, and a DTO?
My understanding is:
MVC Model object:
Models the data to be displayed by a corresponding view. It may not map directly ...
99
votes
11
answers
85k
views
Best Practices For Mapping DTO to Domain Object?
I've seen a lot of questions related to mapping DTOs to Domain Objects, but I didn't feel they answered my question. I've used many methods before and have my own opinions but I'm looking for ...
96
votes
4
answers
130k
views
Difference between Entity and DTO
What is the difference between a DTO and an Entity? In details these are my questions:
What fields should the DTOs have? For example my entity classes are:
@Entity
public class MyFirstEntity ...
87
votes
5
answers
67k
views
DDD - which layer DTO should be implemented
I am learning about DDD so apologies if my question is naive. I think I need to use Local Data Transfer Object in order to display data to the users as a lot of properties are not part of any of ...
61
votes
3
answers
31k
views
Reusing DTO for various request/response types vs explicitness of what is required / what should be returned [closed]
I started wondering on whether I am not falling into an antipattern here, so please advise on the best practices.
I am designing a REST API with a set of various endpoints and I wanted to wrap the ...
53
votes
9
answers
28k
views
DTO or Domain Model Object in the View Layer?
I know this is probably an age-old question, but what is the better practice? Using a domain model object throughout all layers of your application, and even binding values directly to them on the ...
51
votes
2
answers
30k
views
Should the repository layer return data-transfer-objects (DTO)?
I have a repository layer that is responsible for my data-access, which is called by a service layer. The service layer returns DTOs which are serialized and sent over the wire. More often than not, ...
50
votes
2
answers
61k
views
DTO naming conventions , modeling and inheritance
We are building a web app using AngularJS , C# , ASP.Net Web API and Fluent NHibernate.
We have decided to use DTOs to transfer data to the presentation layer ( angular views).
I had a few doubts ...
42
votes
5
answers
9k
views
Value Objects in CQRS - where to use
Let's say we have CQRS-inspired architecture, with components such as Commands, Domain Model, Domain Events, Read Model DTOs.
Of course, we can use Value Objects in our Domain Model. My question is, ...
41
votes
5
answers
25k
views
Which layer should be used for conversion to DTO from Domain Object
We are creating rest api's with Spring Boot. We have three layers in our project(Repository, Service and Controller).
Lets say I have GetUser api in my controller that return UserDTO object.
@...
36
votes
9
answers
25k
views
Nullable reference type in C#8 when using DTO classes with an ORM
I activated this feature in a project having data transfer object (DTO) classes, as given below:
public class Connection
{
public string ServiceUrl { get; set; }
public string? ...
34
votes
8
answers
10k
views
Mapping Validation Attributes From Domain Entity to DTO
I have a standard Domain Layer entity:
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set;}
}
which has some kind of ...
33
votes
5
answers
33k
views
C# MongoDB: How to correctly map a domain object?
I recently started reading Evans' Domain-Driven design book and started a small sample project to get some experience in DDD. At the same time I wanted to learn more about MongoDB and started to ...
33
votes
7
answers
39k
views
DTOs: best practices
I am considering to use DTOs instead of passing around my domain objects. I have read several posts here as well as elsewhere, and i understand there are several approaches to getting this done.
If i ...
32
votes
5
answers
19k
views
Domain vs DTO vs ViewModel - How and When to use them?
In a Multi-layer project with Domain layer (DL)/Business (Service) Layer (BL)/Presentation Layer (PL), what is the best approach to deliver Entities to the Presentation Layer?
DO => Domain Object;
...
32
votes
3
answers
2k
views
How to use ModelMapper for deep inheritance objects?
A.java
@Entity
@Getter
@Setter
@Inheritance
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, inclue=JsonTypeInfo.As.PROPERTY, property="type")
@JsonSubTypes({
@JsonSubTypes.Type(value=AA.class,name="aa"),...
31
votes
6
answers
12k
views
DTO classes vs. struct
So, this is actually this question is my current keystone.
I'm working on refactoring of my personal project, trying increase performance, optimize memory usage, make code easy and clear. I have a ...
30
votes
12
answers
39k
views
@MAPSTRUCT. No property named "packaging" exists in source parameter(s)
I am writing an MVC REST application with Spring Boot and Hibernate. I decided to do DTO mapping using MAPSTRUCT. It seems that I did everything according to the guide, but an error is issued. What is ...
30
votes
7
answers
11k
views
How to quickly check if two data transfer objects have equal properties in C#?
I have these data transfer objects:
public class Report
{
public int Id { get; set; }
public int ProjectId { get; set; }
//and so on for many, many properties.
}
I don't want to write
...
30
votes
8
answers
30k
views
What is the difference between POJO (Plain Old Java Object) and DTO (Data Transfer Object)?
I cannot find difference between them. Does anyone know how to differentiate them?
29
votes
6
answers
24k
views
Python: Quick and dirty datatypes (DTO)
Very often, I find myself coding trivial datatypes like
class Pruefer:
def __init__(self, ident, maxNum=float('inf'), name=""):
self.ident = ident
self.maxNum = maxNum
...
29
votes
2
answers
24k
views
Same/different DTO object in create, update and get rest end points?
Consider following UserDTO class and UserController exposing endpoints to create, update and get User.
Having the id property in the UserDTO class does not make sense for create and update. If I use ...
26
votes
4
answers
30k
views
How to use DTOs in the Controller, Service and Repository pattern
I'm following the Controller, Service and Repository pattern and I'm just wondering where DTOs come into this.
Should the controller only receive DTOs? My understanding is you wouldn't want the ...
26
votes
2
answers
26k
views
What is the difference between DAL, DTO and DAO in a 3 tier architecture style including with MVC
Recently I was learning about ORM (Object Relational Mapping) and the 3 tier architecture style (presentation,business and data persistence).
If I understand correctly, I can separate the data ...
26
votes
4
answers
14k
views
What is the best practice for sending data to the client: POCO or DTO?
I'm starting a project using EF 4 and POCO.
What is the best practice for sending data to the client ? Should I send the POCO or I should have a DTO instead?
Are there any issue I should be aware ...
26
votes
3
answers
13k
views
Should service layer accept a DTO or a custom request object from the controller?
As the title suggests what is the best practice when designing service layers?. I do understand service layer should always return a DTO so that domain (entity) objects are preserved within the ...
25
votes
6
answers
41k
views
Unit testing of DTOs
Is it appropriate and necessary to test getters and setters?
I think they haven't any logic and they can't crash or throw any exceptions.
24
votes
3
answers
8k
views
What format (MIME Type) should I use for HTML5 drag and drop operations?
I'm starting to experiment with HTML5 Drag and Drop. Then, in the dragstart event handler we should run setData(), which receives two parameters: format and data.
function dragstart_handler(ev) {
...
24
votes
1
answer
9k
views
DTO shape: flat, complex/nested, or a mixture of both
I have an MVC2 n-tier application (DAL, Domain, Service, MVC web) using a DDD approach (Domain Driven Design), having a Domain Model with repositories. My service layer uses a Request/Response ...
24
votes
1
answer
18k
views
ApiController vs ODataController when exposing DTOs
Can someone explain me when I should inherit my controller form ODataController vs ApiController ?
The question is caused by the fact that results returned by ApiController can be filtered with OData ...
23
votes
4
answers
56k
views
Json A circular reference was detected while serializing an object of type
Give the classes:
public class Parent
{
public int id {get; set;}
public int name {get; set;}
public virtual ICollection<Child> children {get; set;}
}
[Table("Child")]
public ...
23
votes
4
answers
9k
views
prefixing DTO / POCOS - naming conventions?
simple question really, i was wanting to know what naming conventions anybody puts on there DTO / POCOS ....
I didn't really want to prefix like hungarian notation.. i got away from that!.
But my ...
23
votes
8
answers
60k
views
Entity Framework + AutoMapper ( Entity to DTO and DTO to Entity )
I've got some problems using EF with AutoMapper. =/
for example :
I've got 2 related entities ( Customers and Orders )
and they're DTO classes :
class CustomerDTO
{
public string CustomerID {...
23
votes
2
answers
11k
views
JPA Entities and/vs DTOs
What is the general idea to help deciding when to use DTO and when to use Entity in these cases ?
UI / server side java calling the services. Should it get / send entities or DTOs ?
Web service ...
22
votes
3
answers
6k
views
POCO's, DTO's, DLL's and Anaemic Domain Models
I was looking at the differences between POCO and DTO (It appears that POCO's are dto's with behaviour (methods?))and came across this article by Martin Fowler on the anaemic domain model.
Through ...
22
votes
6
answers
8k
views
Should I map a DTO to/from a domain entity on both client and server sides?
I've got a rich domain model, where most classes have some behaviour and some properties that are either calculated or expose the properties of member objects (which is to say that the values of these ...
22
votes
2
answers
41k
views
Spring DTO validation in Service or Controller?
I'm building a straight forward AJAX / JSON web service with Spring. The common data flow is:
some DTO from browser
v
Spring @Controller method
v
Spring @Service ...
22
votes
4
answers
14k
views
Where to convert a DTO to ViewModel?
I've inherited an MVC2 project using a pretty standard and decently well kept DDD pattern. I've been doing a lot of reading on the whole DTO/ViewModel debate as well.
Currently our DTOs are often ...
22
votes
3
answers
34k
views
Alternative to dozer for bean mapping? [closed]
I am trying to figure out an easy way to map DTOs to entities without the boiler-plate code. While I was thinking of using dozer it appears to require a lot of xml configuration. Has anybody seen a ...
20
votes
2
answers
22k
views
How to manually test input validation with NestJS and class-validator
TLNR: I was trying to test DTO validation in the controller spec instead of in e2e specs, which are precisely crafted for that. McDoniel's answer pointed me to the right direction.
I develop a NestJS ...
20
votes
1
answer
20k
views
How to work with DTO in Spring Data REST projects?
Spring Data REST automates exposing only domain object. But most often we have to deal with Data Transfer Objects. So how to do this in SDR way?
20
votes
6
answers
7k
views
DTOs. Properties or fields?
I need to create some DTO classes to transport our business objects across WCF.
Since these are just bags of data with no functionality, is there any reason I can't just use fields, or is there some ...
19
votes
3
answers
59k
views
Data transfer object pattern
i'm sorry i'm newbie to enterprise application as well as the design pattern. might be this question occcur lack of knowledge about design pattern. i found that its better to use DTO to transfer data.
...