Brandon Clapp
Brandon Clapp

Reputation: 70543

Are JSON objects and DTO the same thing?

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.

Upvotes: 10

Views: 18956

Answers (2)

Zach Smith
Zach Smith

Reputation: 8971

As the answer by Fenton mentions, a DTO (data transfer object) is a concept and not anything specifically

JSON, XML, etc are specifications in themselves which is what I think he means by saying "JSON is the type of serialization. DTO is the serialized object".

Based on a post at martinfowler.com I think it's correct terminology to say "you can serialize DTO as JSON". I.e. a JSON object can be a DTO.

Upvotes: 3

Fenton
Fenton

Reputation: 251062

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.

Upvotes: 11

Related Questions