Questions tagged [dto]

DTO is an acronym for Data Transfer Object, a design pattern used in data transfer.

DTO is an acronym for Data Transfer Object, a design pattern used in transferring data through internal or external interfaces. A DTO protects the application's internal data by acting as dummy storages, the whole logic is implemented only in actual Domain Objects (DO).

Pros:

  • Fewer remote calls (typically one, getDto() vs. individual getId(), getName(), etc.)
  • Improved data capsulation (Remote systems need only to know the details of the DTO, not DO internals)

Cons:

  • class explosion
  • conversions needed between DTOs and DOs
2100 questions
17
votes
2 answers

JPA merge in a RESTful web application with DTOs and Optimistic Locking?

My question is this: Is there ever a role for JPA merge in a stateless web application? There is a lot of discussion on SO about the merge operation in JPA. There is also a great article on the subject which contrasts JPA merge via a more manual…
Dave
  • 21,524
  • 28
  • 141
  • 221
16
votes
2 answers

How to write nested DTOs in NestJS

I am a beginner in NestJS and I want to write a DTO for below structure - { something: { info: { title: string, score: number, description: string, time: string, DateOfCreation:…
user3399180
  • 476
  • 2
  • 7
  • 18
16
votes
1 answer

Should DTOs use inheritance or composition

In SOA if a few DTO classes have some fields that are repeated across. Is it better to use Composition or Inheritance so there is not repetition OR just use one DTO class that encapsulates all fields.As my DTO classes grow I see lot of repetitive…
pingu
  • 645
  • 3
  • 11
  • 21
16
votes
5 answers

DTO and mapper generation from Domain Objects

I have plenty of java domain objects that I need to transform to DTOs. Please, don't start with the anti-pattern thing, the Domain Objects are what they are because of a long history, and I can't modify them (or not too much, see below). So, of…
Nicolas C
  • 944
  • 1
  • 10
  • 22
16
votes
2 answers

Translating Entity Framework model navigation properties into DTOs

I’m currently working on an n-tier web project. After researching into Data Transfer Objects and their benefits we decided to give this pattern a go. Our ASP.NET MVC website does not have direct access to the EF DbContext but instead will use DTOs…
Chris White
  • 233
  • 2
  • 13
15
votes
10 answers

MapStruct implementation is not working in Spring Boot Web Application

I am a newbie to Spring Boot and MapStruct Tool. Earlier, A Project(written by other team using these technologies) is not starting up. Then, I had made some changes in Mapper Abstract Class but now mapper object is coming as null on application…
Ankit
  • 2,126
  • 4
  • 33
  • 53
14
votes
1 answer

Has Chrome improperly implemented the dataTransfer object?

When I do this in dragstart event: e.dataTransfer.setData('text/plain', 'text'); e.dataTransfer.setData('text/html', 'html'); e.dataTransfer.setData('application/x-bookmark', 'bookmark'); and this in drop event: for (var i = 0; i <…
Shinjikun
  • 590
  • 1
  • 5
  • 13
13
votes
5 answers

How can I validate an array of enum values with Nestjs

I feel like a combination of this thread and this thread is what I need to implement, I'm having trouble drawing them together. I have a DTO that contains an enum. Using Postman, I am sending a PurchasableType of FOO and expecting to get an error of…
Damon
  • 4,151
  • 13
  • 52
  • 108
13
votes
1 answer

Is there any naming convention for IN and OUT DTO?

If I had to create some sort of API with a MVC architechture, I would have to decide a naming convention for DTOs that the controller receive and those DTOs that the controller produces I'm right? For example, given the following code: public class…
Rod Ramírez
  • 1,138
  • 11
  • 22
13
votes
4 answers

NestJs - DTO and Entities

I'm trying to use cleverly DTO and Entities in my project but it seems more complicated than it should be. I'm building a backend for managing inventory, I use NestJs and TypeOrm. My client is sending me a set of data throught a POST request, let's…
Yanover
  • 163
  • 1
  • 3
  • 13
13
votes
7 answers

DTO conveter pattern in Spring Boot

The main question is how to convert DTOs to entities and entities to Dtos without breaking SOLID principles. For example we have such json: { id: 1, name: "user", role: "manager" } DTO is: public class UserDto { private Long id; private…
Maksym
  • 2,650
  • 3
  • 32
  • 50
13
votes
2 answers

Should I have different DTOs for Create and Update? (CRUD)

I'm designing a Web API with the usual CRUD operations on a Person entity. The problem is that I don't know how to design the DTOs. The entity is as follows: public class Person { public int Id { get; set; } public string Name { get; set;…
SuperJMN
  • 13,110
  • 16
  • 86
  • 185
13
votes
3 answers

Should I use DTOs as my data models in MVVM?

I'm currently working on what will be my first real foray into using MVVM and have been reading various articles on how best to implement it. My current thoughts are to use my data models effectively as data transfer objects, make them serializable…
JonC
  • 809
  • 8
  • 18
13
votes
2 answers

Symfony2 DTO, Entity conversion

I'm creating symfony2 application with doctrine2 and I would like to ask for advice regarding common/good practice for DTO-Entity, Entity-DTO conversion. I've found some information for all languages and frameworks, but none for SF2. I would like to…
13
votes
1 answer

AutoMapper flattening of nested mappings asks for a custom resolver

I'm somewhat new to AutoMapper and wanted to map a POCO-ish object to a perhaps more complex DTO, the latter tries to be a representation of a Google Books API's Volume resource: Book.cs public class Book { public string Isbn10 { get; set; } …
Nano Taboada
  • 4,148
  • 11
  • 61
  • 89