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
0
votes
0 answers

Is this good practise for Generic-Typesafety in Java?

This is the first time I tried to use generics and luckily, it works for me, but I don't know if this is really supposed to be like this (below) or if there is another - more elegant - way to solve this nestings/abstraction. If so, could you please…
getnosleep
  • 1
  • 1
  • 4
0
votes
1 answer

Java Spring: automatic EntityToDTO mapping using a method instead of an attribute

In Spring there's this nice automatic convertion between entities and DTOs: @Mapping(source = "senderId", target = "senderId") @Mapping(source = "text", target = "text") MessageGetDTO convertEntityToMessageGetDTO(Message message); Here we have the…
Duke
  • 386
  • 2
  • 13
0
votes
1 answer

org.hibernate.MappingException: Unknown entity - Hibernate, SpringBoot, DTO pattern

I am trying to build a simple SpringBoot and Hibernate app using DAO and DTO pattern. I am trying to save a list of users to the database. When I am using User class it works fine, but when I am trying to use DTO CreateUserDto class I am getting the…
user9347049
  • 1,927
  • 3
  • 27
  • 66
0
votes
1 answer

RestTemplate Project: the DTO fields changing on their own

So I made Rest Client using Spring Boot that is consuming a Rest Web Service. I am passing the required requestbody but on printing the requestbody out it is not the same as my input. For Example: What I entered was TransactionId then it would be…
0
votes
2 answers

How to return enum in the DTO?

I have an Order entity: public class Order { private String name; private Status status;//enum //other fields, getters,setters } Status is the enum with a lot of values(let's imagine 30 statuses). I created OrderDto and OrderMapper. I want…
Pavel Petrashov
  • 1,073
  • 1
  • 15
  • 34
0
votes
1 answer

Nestjs - Possible to get properly instantiated body payload?

Nestjs documentation advises to use classes instead of interfaces for the DTO's because they are preserved as real entities in the compiled JavaScript but in reality the payload classes are not properly instantiated (with new()), they are Objects…
Stefaan Vandevelde
  • 339
  • 1
  • 4
  • 7
0
votes
0 answers

How to deserialize single JSON field with Jackson, having JSON path and DTO?

Having JSON path String, like "foo.bar[1].baz", and corresponding DTO class in Java, how can I implement a generic method, that would deserialize single field like ObjectMapper#readValue(String,Class) would? By "corresponding DTO" I mean DTO for…
0
votes
2 answers

Many-to-many relationship error in ASP.NET MVC

I am new to ASP.NET MVC, and I'm creating an app for attending music events. There is a button for user to follow an artist to get all upcoming events. When clicking on that button I get an error: Entities in 'ApplicationDbContext.Followings'…
ibrahim
  • 135
  • 3
  • 9
0
votes
1 answer

Register Api Controller is not saving the hashed password

Yesterday, my coworker accidently deleted the database. I deleted my old migration folder and re-migrated to the database using the same code. When I attempt to register a new dummy user, the Hashed password in the database is registered as null…
Nour Mawla
  • 33
  • 1
  • 10
0
votes
1 answer

List of Generics for DTO

I'm building a WebAPI projet in .Net Core 5. The output is always paginated results for all the endpoints. Therefore I've created a DTO for the paginated output like the following: public class PagedCommodityListDto { /// /// The…
Giox
  • 4,785
  • 8
  • 38
  • 81
0
votes
1 answer

Web Api returns same data multiple times

public class VillageDto { public int id { get; set; } public string Name { get; set; } public string HindiName { get; set; } public int CentreId { get; set; } } public class CentreDto { public int id { get; set; } …
0
votes
0 answers

How can I flexibly compose classes together in TypeScript?

I have a NestJS app where I need to define entities (classes that serve as Mongoose schemas) and DTOs (classes that define the API request/response shapes). There are times where these 2 classes are nearly identical, like when you need to create a…
Greg Thomas
  • 397
  • 3
  • 13
0
votes
1 answer

Can I use a single entity for multiple tables?

I have multiple tables in database with exactly same columns and signature. All the tables are created based on year like all the data for 2020 is in one table and for 2021 it's in other table. Is it possible to use the a single entity for multiple…
aakarvind
  • 1
  • 2
0
votes
1 answer

Best data type to use to map JSON arrays to DTOs in C# / ASP .Net Core

This is probably a dumb question, but I was wondering the following: I have a .Net 5 Web API, and in it I want to create a DTO to accept a POST request from a front end. The body in the POST request contains the following JSON: { "aComment":…
Fabricio Rodriguez
  • 3,769
  • 11
  • 48
  • 101
0
votes
1 answer

Spring Boot Pagination with DTO returned in response

I have a spring boot application with @RestController and within that I got a @GetMapping Method, in which I return a List of DTOs from a Native Query to my Client. Now I wanted to add pagination. But since my Method is not returning an entity but…
1 2 3
99
100