Skip to content

Commit

Permalink
Register for reflection Pageable class for not missing paged/unpaged …
Browse files Browse the repository at this point in the history
…attributes.

Related to quarkusio#41292
  • Loading branch information
aureamunoz committed Dec 17, 2024
1 parent d7b25ed commit 57c250d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void registerReflection(BuildProducer<ReflectiveClassBuildItem> 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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,6 +48,12 @@ public interface BookRepository extends Repository<Book, Integer> {
@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<Book> findPaged(Pageable pageable) {
List<Book> list = findAll();
return new PageImpl<>(list, pageable, list.size());
}

interface BookCountByYear {
int getPublicationYear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -115,4 +119,10 @@ public Integer customFindPublicationYearObject(@PathParam("bid") Integer bid) {
return bookRepository.customFindPublicationYearObject(bid);
}

@GET
@Path("/paged")
public Page<Book> getPaged(@QueryParam("size") int size, @QueryParam("page") int page) {
return bookRepository.findPaged(PageRequest.of(page, size));
}

}
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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");
}
}

0 comments on commit 57c250d

Please sign in to comment.