Tài Bùi
Tài Bùi

Reputation: 1

How to return list DTO contains a list of other DTO

I'm new in dev web so if I make mistake, pardon me!. I have a Category DTO 1-n relate with Category Item DTO, two of them have two field ID and Name. If client call API to get all Category Item, I want to return list Category contain list of Category Item ralate by CategoryID. How can I excute that in DTO?

the JSON file return like: https://i.sstatic.net/AeJmC.jpg

Upvotes: 0

Views: 2060

Answers (1)

Dougllas Sousa
Dougllas Sousa

Reputation: 107

Add a List of CategoryItemDTO to your Category DTO , so your Category class should get like this:

class Category{
   Long uid;
   String name;
   List<CategoryItemDTO> categoryItems;
}

Upvotes: 1

Related Questions