Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are JSON objects and DTO the same thing?

Tags:

json

dto

Are JSON objects and DTO (data transfer objects) the same thing, or are they completely different? In the case of a REST architecture, the incoming HTTP requests can be be sent as JSON from the client, then serialized to CLR objects once they are received on server end.

In this particular case, would the JSON be considered the DTO, or would the serialized object be refereed to as the DTO?

I'm very new to data transfer between multiple systems, so I appreciate the help.

like image 451
Brandon Clapp Avatar asked Feb 18 '23 19:02

Brandon Clapp


1 Answers

A DTO is simply a design pattern for representation of data and can be formatted as JSON, XML or even something else.

JSON is the type of serialization. DTO is the serialized object.

Aside: JSON does more than just data-transfer, but I don't think that detail is important in the context of your question. What is important is that if you use the behavioural aspects of JSON, you are no longer dealing with a DTO as a DTO should be behaviour-less.

like image 112
Fenton Avatar answered Feb 27 '23 13:02

Fenton