Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [dto]

Data Transfer Objects are for moving data between processes.

2
votes
4answers
205 views

C# class naming convention for a single item in the item list [closed]

In my C# project, I have a domain class named 'User'. this class will contain user's id, firstname, last name, DoB, home address, phone, etc. And we also have a typical REST web api (i.e. api/users) ...
10
votes
2answers
839 views

Clean Architecture: What is the View Model?

In his book 'Clean Architecture', Uncle Bob says that the Presenter should put the data that it receives into something he calls the 'View Model'. Is this the same thing as the 'ViewModel' from the ...
1
vote
0answers
145 views

How to simplify design and remove duplication in java layered architecture?

I've the following project structure (simplified): domain dto view In domain model is kept. dto classes are used to pass data from domain to view. And in view I've a controller and a handful of *req,...
0
votes
1answer
230 views

DTO vs. read model

If I understand the concept of read models correctly, then it's just a simple query to return a use case specific data set. But a DTO seems to have the same purpose, but in a more complex way (...
1
vote
1answer
191 views

Is it okay to transport a DTO inside of a DTO?

Let's suppose we have to entities, X and Y where Y is part of X, being this: class X { private int fooX; private List<Y> fooY; } class Y { private long barX; private int ...
1
vote
2answers
206 views

What data should a repository return

I have a simple project where the controller calls the service, and the service calls the repository in order to get the needed data. Assuming that we have these domain models: // this model has a ...
9
votes
6answers
694 views

Is separating most classes into DTO and helper classes (if possible) a good or an anti-pattern?

For example, a class usually have class members and methods, eg: public class Cat{ private String name; private int weight; private Image image; public void printInfo(){ ...
0
votes
0answers
141 views

Should I add XML comments in DTO models or entity models

I have 2 models, DTOs and database models (entities) that map to the database. I usually put XML comments above the properties to describe what are they for. class MyEntity { /// <summary> ...
3
votes
1answer
1k views

Use DTO Pattern or Serialize Domain Objects

A colleague of mine is against using DTOs and rather feels we should just return Entity / Domain objects serialized for a REST api. He feels DTO is an anti pattern and sited this article Data Transfer ...
1
vote
1answer
3k views

Data Objects for each layer(DTO vs Entity vs Response objects)

Let's say I'm building a Customer web application(in Spring Boot 2), which also exposes rest end points. I'm modeling my application into 3 layers. 1) a) UI - CustomerDTO b) REST - ...
1
vote
1answer
100 views

Data transfer between modules (layers)

I'm creating an application that is composed using different modules (core, course, grades, news). I'm using clean architecture for the different modules but I'm stuck trying to pass data from one ...
0
votes
0answers
501 views

Approaches to writing object converters / translators

I've been going back and forth on what approach to take with conversion code (for example code that translate a POJO into a DTO and vice versa). I am currently working in Java but I suppose some of ...
2
votes
0answers
573 views

How to avoid DTO on a client/server application?

I would like to use DRY beans on my client-server application (DRY: Dont Repeat Yourself). It is not a problem to me if it is highly coupled: I know that my DTO will have the same form as the ...
1
vote
2answers
1k views

Can DTO contain additional helper methods?

I have a DTO like below class OnlineProfileDTO { @JsonProperty("likes") SummaryDTO likes; // lots of other complex fields similar to above } class SummaryDTO { @JsonProperty("count") int ...
1
vote
2answers
110 views

Comparing approaches of mapping data objects

Update: I added some diagrams to help understanding I had a discussion with a colleague about two different approaches in mapping data objects. I'd like to get your opinion on pros and cons between ...
10
votes
3answers
3k views

Ways to share DTO across microservices?

My scenario is as follows. I am designing a system designed to receive data from various types of sensors, and convert and then persist it to be used by various front-end and analytics services later....
1
vote
2answers
227 views

Should a REST CRUD Service that accesses a DB have 3 versions of its model

I'm building a REST service in java that does basic CRUD operations on Customers. The easy way would be for me to create one Customer model, and annotate it with JPA annotations so my persistence ...
0
votes
1answer
227 views

DTO to hold disparate data from domain model?

I have a neat domain model that makes it easy to communicate with an external web service. New requirements have made the external web service's interface messy and now I have to gather data from ...
6
votes
1answer
367 views

Should DTO have same structure as payload?

I have a usecase where I am supposed to store entire payload from a third party API in addition to the DTO, say XYZDto, its translated to. There are two ways to achieve that - Translate the payload ...
0
votes
1answer
374 views

How to handle mapping from object model to different versions of contracts or DTO's

I'm looking for patterns or best practices for maintaining different versions of an API contract. There's lots of information on the internet about how to version API's (URL's vs. headers etc), but ...
2
votes
3answers
2k views

C# - Initialize DTOs in constructor or via properties?

I was wondering if there is a recommended approach to initializing the properties of a plain object that is used for data transfer, for example via a REST-API. Here are two variants I can think of: ...
4
votes
1answer
2k views

Which C# type should one prefer for defining lists in DTOs?

I was wondering if there is a recommended approach to defining a property of a plain object that is used for data transfer, for example via a REST-API which is a list of other objects. Which C# type ...
0
votes
0answers
1k views

Pattern for DTO/Assembler

I am working on a CRUD application in Java (DropWizard). I chose a pretty typical layered architecture with the following layers: Domain Layer (Entities, DAOs), Application Layer (Services) and ...
9
votes
4answers
5k views

Use composition and inheritance for DTOs

We have a ASP.NET Web API that provides a REST API for our Single Page Application. We use DTOs/POCOs to pass data through this API. The problem is now, that these DTOs are getting bigger over time, ...
0
votes
1answer
472 views

Should I call this a DTO or something else?

In a Java/Spring MVC/Hibernate application I have model objects that contain references to other model objects where the database has foreign keys. So for example, I might have: @Entity @Table(name="...
0
votes
1answer
312 views

Is it advisable to use hashes as DTOs in Ruby when applying DDD?

It seems to me that Ruby hashes would be a good option to implement the Data Transfer Objects that the Application Services receive from the client code as commands and queries requests. For ...
0
votes
1answer
697 views

Where to put the behaviour of DTOs ? Object vs Data structure clean code

Similar question was posted here https://stackoverflow.com/questions/21064164/clean-code-how-to-design-this-class I still don't find an answer though, I'm confused! I read the book "clean code" too....
3
votes
1answer
649 views

How do you define Domain Objects and Repositories, when dealing with multiple database tables?

Imagine an application that allows you to add line items to a quote. The end result is like a sales person giving you a printed sheet with information such as name of the business, name of the sales ...
-1
votes
1answer
384 views

CQRS + Event sourcing - event groups and event propagation

This is my current CQRS use-case setup: Command DTO is received in application layer handler where we map Command DTO to appropriate domain objects if needed, re-hydrate aggregate root from repo and ...
14
votes
3answers
7k views

Sharing DTO objects between microservices

TL;DR - Is it ok to share a POJO library between services? Generally we like to keep the sharing between services strictly limited to none if possible. There has been some debate whether or not the ...
3
votes
1answer
813 views

How to name method specific DTOs representing the same entity?

I'm building a Web API. To give meaning to my controller methods I want classes that specify what properties are used for each particular operation. This would make the code easier to understand, and ...
3
votes
2answers
741 views

Using a superset DTO for a number of methods in a class

Consider a class with a number of methods that are required to return a number of values each. In a strongly typed language such as C#, we can have the effect of returning more that one value from a ...
7
votes
1answer
580 views

Reusing a top-level DTO as a child in another DTO

What is the recommendation regarding re-using DTO's as a child in another DTO? I'm using ASP.NET Web API (C#) and consuming the results with Angular 1.x (not sure if that really matters). I have the ...
1
vote
1answer
442 views

Passing information between an Adapter and the Application Layer on Hexagonal Architecture

After starting the design of a sample application with Hexagonal Architecture I got to the application layer that should be basically an API to manipulate the domain in some way. My question is: In ...
1
vote
0answers
42 views

One service facade per view

I am currently trying to design a Java EE web application. The views are quite complex, i.e. several dynamic drop down menus. The content of those drop downs may depend on the internal state of the ...
3
votes
2answers
731 views

Composition of Data Transfer Objects

Let's say I want to create a shop/order system. I'll have an Order DTO to which I'll map the data from a request and results from the database. The object will consist of an order number, a customer ...
1
vote
2answers
737 views

Creating a client side database to store consumed web services?

I have been developing android application for a while now. What we currently do is we first develop our UI components in the mean time web API developers will be completing the web APIs required, so ...
0
votes
1answer
364 views

Better way to transform data [closed]

Context Imagine complicated service that provides info about bank products, fees and so on. Imagine complicated UI that deals with it. UI and Service data formats are changed 1-2 times/month because ...
1
vote
1answer
149 views

Converting data in setters in a DTO

I wrote a simple DTO to transfer data from one point to another, or so was the initial thought. Now I just caught myself in the act of doing various things in the DTO, for simplicity's sake, like ...
0
votes
1answer
471 views

Should API DTOs be shaped to client(s) or be universal?

I have a project with an internal desktop client app and a server-side client API service talking to a relational database. I seem to have two choices: 1) shape DTOs to client views, e.g. ...
1
vote
1answer
411 views

Should DTO have validators?

I believe that DTO should be as dummy and easy as possible. However, after hint made by my friend, opportunity to validate data that is set in DTO sounds tempting. Let's have following example: //...
1
vote
1answer
925 views

DTO and JPA Version

I have DB tables representing Employees and Departments. The server side(JavaEE) contains JPA entities representing the same. The client is a standalone client and communicates with the server using ...
2
votes
1answer
883 views

Is a class representing a JSON response a DTO, a domain object, or something else?

Consider a restful service in Spring MVC. I am wondering how to package my response classes, i.e. how to name the containing package. First I thought of them as being domain objects. But they are ...
2
votes
2answers
7k views

What is the best way to create DTOs from entities and update entities from DTOs in a layered architecture?

Option 1: At first I would make a call to my service layer, which served as an API for my core domain, to get a domain object or a list of domain objects and then pass them into the assembler which ...
0
votes
0answers
53 views

What is the best way to create DTOs from entities and update entities from DTOs in a layered architecture? [duplicate]

Option 1: At first I would make a call to my service layer, which served as an API for my core domain, to get a domain object or a list of domain objects and then pass them into the assembler which ...
4
votes
2answers
5k views

When is it appropriate to map a DTO back to its Entity counterpart

From what I've read and implemented, DTO is the object that hold a subset of value from a Data model, in most cases these are immutable objects. What about the case where I need to pass either new ...