Как преобразовать результат JpaRepository в мой пользовательский класс DTO - PullRequest
0 голосов
/ 25 февраля 2019

Я хочу преобразовать страницу в страницу

, поэтому я реализовал вот так

@GetMapping("/history")
public Page<ResponseAllHistoryDto> getAllHistory() {
    Pageable pageable = PageRequest.of(0, 20, Sort.by("createdAt"));
    Page<History> histories = historyRepository.findAll(pageable);
    return histories.map(history -> {
       return ResponseAllHistoryDto.builder()
               .history(history)
               .tags(tagRepository.findByHistoryHistoryId(history.getHistoryId()))
               .auths(authRepository.findByHistoryHistoryId(history.getHistoryId()))
               .build();
    });
}

К сожалению.Это дает мне

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.wrapsody.demo.ResponseAllHistoryDto and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.data.domain.PageImpl["content"]->java.util.Collections$UnmodifiableRandomAccessList[0])

в чем проблема ....: (

1 Ответ

0 голосов
/ 25 февраля 2019

Вы DTO класс должен иметь конструктор по умолчанию, геттеры и сеттеры.Попробуйте аннотировать это с помощью lombok's @Data.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...