Skip to content
Advertisement

How to map Iterable to its DTO?

I have the following repository:

PermissionRepository:

JavaScript

In my service, I am trying to map Permission entity to PermissionDTO, but as findAll() method returns Iterable<T> (Iterable<T> findAll();), I cannot convert as shown below as I generally use for List<T>. It throws “Cannot resolve method ‘stream’ in ‘Iterable’” error for the .stream() method.

JavaScript

So, how can I map this Permission entity to PermissionDTO?

Advertisement

Answer

There are 3 ways to do what you want

Override findAll and make it return a List

JavaScript

Implement JpaRepository instead of CrudRepository.

JavaScript

Convert Iterable to Stream using StreamSupport.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement