From dda0b149b4181db10de06e7657f1e37788ad0118 Mon Sep 17 00:00:00 2001 From: Auri Munoz Date: Fri, 13 Dec 2024 12:23:23 +0100 Subject: [PATCH] Register for reflection Pageable class for not missing paged/unpaged attributes. Related to #41292 (cherry picked from commit 57c250d70157074941a0fa5fe7fc99ffc8b8d324) --- .../data/deployment/SpringDataJPAProcessor.java | 1 + .../it/spring/data/jpa/BookRepository.java | 9 +++++++++ .../quarkus/it/spring/data/jpa/BookResource.java | 10 ++++++++++ .../it/spring/data/jpa/BookResourceTest.java | 16 ++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/SpringDataJPAProcessor.java b/extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/SpringDataJPAProcessor.java index 104d9167067b7..2b893982be4f0 100644 --- a/extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/SpringDataJPAProcessor.java +++ b/extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/SpringDataJPAProcessor.java @@ -103,6 +103,7 @@ void registerReflection(BuildProducer producer) { "org.springframework.data.domain.Page", "org.springframework.data.domain.Slice", "org.springframework.data.domain.PageImpl", + "org.springframework.data.domain.Pageable", "org.springframework.data.domain.SliceImpl", "org.springframework.data.domain.Sort", "org.springframework.data.domain.Chunk", diff --git a/integration-tests/spring-data-jpa/src/main/java/io/quarkus/it/spring/data/jpa/BookRepository.java b/integration-tests/spring-data-jpa/src/main/java/io/quarkus/it/spring/data/jpa/BookRepository.java index e68d9c856ff73..e6802086398c1 100644 --- a/integration-tests/spring-data-jpa/src/main/java/io/quarkus/it/spring/data/jpa/BookRepository.java +++ b/integration-tests/spring-data-jpa/src/main/java/io/quarkus/it/spring/data/jpa/BookRepository.java @@ -3,6 +3,9 @@ import java.util.List; import java.util.Optional; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.Repository; import org.springframework.data.repository.query.Param; @@ -45,6 +48,12 @@ public interface BookRepository extends Repository { @Query(value = "SELECT b.publicationYear FROM Book b where b.bid = :bid") Integer customFindPublicationYearObject(@Param("bid") Integer bid); + // Related to issue 41292 + public default Page findPaged(Pageable pageable) { + List list = findAll(); + return new PageImpl<>(list, pageable, list.size()); + } + interface BookCountByYear { int getPublicationYear(); diff --git a/integration-tests/spring-data-jpa/src/main/java/io/quarkus/it/spring/data/jpa/BookResource.java b/integration-tests/spring-data-jpa/src/main/java/io/quarkus/it/spring/data/jpa/BookResource.java index 55e6342d340e3..2db6fcd4d5f73 100644 --- a/integration-tests/spring-data-jpa/src/main/java/io/quarkus/it/spring/data/jpa/BookResource.java +++ b/integration-tests/spring-data-jpa/src/main/java/io/quarkus/it/spring/data/jpa/BookResource.java @@ -8,8 +8,12 @@ import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; import jakarta.ws.rs.Produces; +import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.core.Response; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; + @Path("/book") public class BookResource { @@ -115,4 +119,10 @@ public Integer customFindPublicationYearObject(@PathParam("bid") Integer bid) { return bookRepository.customFindPublicationYearObject(bid); } + @GET + @Path("/paged") + public Page getPaged(@QueryParam("size") int size, @QueryParam("page") int page) { + return bookRepository.findPaged(PageRequest.of(page, size)); + } + } diff --git a/integration-tests/spring-data-jpa/src/test/java/io/quarkus/it/spring/data/jpa/BookResourceTest.java b/integration-tests/spring-data-jpa/src/test/java/io/quarkus/it/spring/data/jpa/BookResourceTest.java index 3bd490e6594ee..318cd12659c13 100644 --- a/integration-tests/spring-data-jpa/src/test/java/io/quarkus/it/spring/data/jpa/BookResourceTest.java +++ b/integration-tests/spring-data-jpa/src/test/java/io/quarkus/it/spring/data/jpa/BookResourceTest.java @@ -1,13 +1,17 @@ package io.quarkus.it.spring.data.jpa; +import static io.restassured.RestAssured.given; import static io.restassured.RestAssured.when; +import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.core.Is.is; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import io.quarkus.test.junit.QuarkusTest; +import io.restassured.response.Response; @QuarkusTest public class BookResourceTest { @@ -132,4 +136,16 @@ void testCustomFindPublicationYearObject() { .statusCode(200) .body(is("2011")); } + + @Test + void testEnsureFieldPageableIsSerialized() { + Response response = given() + .accept("application/json") + .queryParam("size", "2") + .queryParam("page", "1") + .when().get("/book/paged"); + Assertions.assertEquals(200, response.statusCode()); + assertThat(response.body().jsonPath().getString("pageable")).contains("paged:true"); + assertThat(response.body().jsonPath().getString("pageable")).contains("unpaged:false"); + } }