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

Use Entity in place of DTO inside reciever service

Basically i have this service A that sends a DTO to the service B. What i did is the following: 1) B recieves the DTO from a. 2) B converts the DTO to an Entity 3) B uses the Entity (has an in-memory db). I did this way because i deal with an…
0
votes
1 answer

imported class with class-validator annotration is not validated by Validation pipe

I have a simple nest controller with validation pipe decorator import {GetCatDto} from 'my-shared-lib' @Controller('myController') export class MyController { constructor(private readonly policyManagerService: PolicyManagerService) {} @Get() …
Lior Baber
  • 852
  • 3
  • 11
  • 25
0
votes
3 answers

What is the correct way to use Spring Boot ConversionService in order to convert a retrieved list of entity objects into a list of DTOs objects?

I am working on a Spring Boot application and I have the following doubt. I have this service method (that works fine) that insert an object into the DB calling the repository: @Override @Transactional public CoinDTO createCoin(CoinDTO coin) throws…
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
0
votes
4 answers

How can I change the value of the fields for a generated POJO using Lombok?

I'm using Lombok for POJOs generation, so how can I change the value of the fields? @Value @AllArgsConstructor @NoArgsConstructor(force = true, access = AccessLevel.PRIVATE) @Builder(toBuilder = true, builderClassName = "builder") public class…
Razvan
  • 347
  • 1
  • 11
0
votes
4 answers

Post method not reading json, only String in Spring Boot api

i'm developing a simple CRUD api but my post method is not working, everytime a send data with json format it throws this exception { "title": "Cannot construct instance of `academy.devdojo.springboot2.requests.AnimePostRequestBody` (although at…
0
votes
1 answer

How to convert DTO to an entity with a related column

This is probebly a repetition to my yesturday's question here Can't save data to a database with DTO I can get a request as DTO. But then I convert it to a model class back I get value of regionid column as null. My DTO Class package…
Bogdan Onyshenko
  • 415
  • 1
  • 6
  • 24
0
votes
3 answers

Should I create multiple DTOs for the same entity?

(Sorry my English is so bad). The user entity in my spring boot project has the following basic fields: id, name, email, role, password. Admin can create new employee (including password field), update employee (except for password field), view…
DragonVN
  • 21
  • 4
0
votes
0 answers

Access DTO and Struct using string variable in Go

I am trying to set some timestamps based off values in a struct and the dto in Go. I think I may need to use reflection here, but I am a beginner in Go and not quite sure how to attack this. Here's a glimpse of my existing code. I have approximately…
bondra76
  • 99
  • 7
0
votes
1 answer

Spring: DTO file size validation

Consider two controller endpoint methods: @RestController public class MyController { @PostMapping("/foo") public ResponseEntity foo(@Valid @RequestBody FooDto dto) { // .. } @PostMapping("/bar") public ResponseEntity
weno
  • 804
  • 8
  • 17
0
votes
0 answers

Add additional fields into doctrine result (DTO)

Im trying to get the best rated movies by average from my database and hydrate them nicely into a DTO with doctrine so i can work well later with it and integrate them e.g. into my api with api platform. I already managed to get it work with a raw…
0
votes
1 answer

Default boolean setting in DTO

I want to define default false for boolean but it seems still true as default on swagger. How could I define this to see false as default. Swagger request : { "transferList": [ { "reverseFlag": true, "transactionId": 0 } …
Neslihan Bozer
  • 179
  • 3
  • 12
0
votes
1 answer

Manual Mapping with Inhertance

let assume I have two classes A and ADto. A inherits from ABase and ADto inherits from ADtoBase. I have two extension methods for manually mapping ABase to ADtoBase and vice versa. When I want to write an extension method to map A to ADto, is there…
Jeff
  • 1
0
votes
0 answers

Which annotations should I use in request & response class in Java?

I have been confused due to the different usages and annotations for request & response class in Java. Some of them use @Value, some others @Data. Similarly some of them @RequiredArgsConstructor, some others @AllArgsConstructor. So, could you pleae…
user17186249
0
votes
1 answer

NET Core 6 Trouble updating a DB record using a DTO

This is my first time using DTO's to transfer data to the DB. I have this Create method that uses a DTO (I wont show that DTO because this is just an example) and works fine: [HttpPost] [ValidateAntiForgeryToken] public async…
0
votes
1 answer

Nest js: How to received a dto field with array of predefined strings

I have a dto which is called product and it has a field called units....which received array of strings and this strings are predefined..... my valid strings are predefined in a array ... let validItems = ['a', 'b', 'c', 'd', 'e'] the data I want…
Riyad Zaigirdar
  • 691
  • 3
  • 8
  • 22