diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PageableSpringEncoder.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PageableSpringEncoder.java index 92366c83..916044f1 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PageableSpringEncoder.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PageableSpringEncoder.java @@ -116,7 +116,7 @@ public class PageableSpringEncoder implements Encoder { } } for (Sort.Order order : sort) { - sortQueries.add(order.getProperty() + "," + order.getDirection()); + sortQueries.add(order.getProperty() + "%2C" + order.getDirection()); } if (!sortQueries.isEmpty()) { template.query(sortParameter, sortQueries); diff --git a/spring-cloud-openfeign-core/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-openfeign-core/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 577a75b1..98ff39ae 100644 --- a/spring-cloud-openfeign-core/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-openfeign-core/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -2,6 +2,12 @@ "groups": [ ], "properties": [ + { + "name": "feign.autoconfiguration.jackson.enabled", + "type": "java.lang.Boolean", + "description": "If true, PageJacksonModule and SortJacksonModule bean will be provided for Jackson page decoding.", + "defaultValue": "false" + }, { "name": "feign.circuitbreaker.enabled", "type": "java.lang.Boolean", diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java index 656c06ba..b69776d4 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java @@ -16,6 +16,7 @@ package org.springframework.cloud.openfeign.encoding; +import java.util.List; import java.util.Optional; import org.junit.Test; @@ -53,6 +54,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen * Tests the pagination encoding. * * @author Charlie Mordant. + * @author Hyeonmin Park */ @SpringBootTest(classes = FeignPageableEncodingTests.Application.class, webEnvironment = RANDOM_PORT, value = { "feign.compression.request.enabled=true", "feign.autoconfiguration.jackson.enabled=true" }) @@ -86,6 +88,64 @@ public class FeignPageableEncodingTests { } + @Test + public void testPageableWithDescDirection() { + // given + Pageable pageable = PageRequest.of(0, 10, Sort.Direction.DESC, "sortProperty"); + + // when + final ResponseEntity> response = this.invoiceClient.getInvoicesPaged(pageable); + + // then + assertThat(response).isNotNull(); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getBody()).isNotNull(); + assertThat(pageable.getPageSize()).isEqualTo(response.getBody().getSize()); + + Sort sort = response.getBody().getPageable().getSort(); + assertThat(sort).hasSize(1); + assertThat(sort.get()).hasSize(1); + + Optional optionalOrder = sort.get().findFirst(); + assertThat(optionalOrder.isPresent()).isTrue(); + + Sort.Order order = optionalOrder.get(); + assertThat(order.getDirection()).isEqualTo(Sort.Direction.DESC); + assertThat(order.getProperty()).isEqualTo("sortProperty"); + + } + + @Test + public void testPageableWithMultipleSort() { + // given + Pageable pageable = PageRequest.of(0, 10, + Sort.by(Sort.Order.desc("sortProperty1"), Sort.Order.asc("sortProperty2"))); + + // when + final ResponseEntity> response = this.invoiceClient.getInvoicesPaged(pageable); + + // then + assertThat(response).isNotNull(); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getBody()).isNotNull(); + assertThat(pageable.getPageSize()).isEqualTo(response.getBody().getSize()); + + Sort sort = response.getBody().getPageable().getSort(); + assertThat(sort).hasSize(2); + + List orderList = sort.toList(); + assertThat(orderList).hasSize(2); + + Sort.Order firstOrder = orderList.get(0); + assertThat(firstOrder.getDirection()).isEqualTo(Sort.Direction.DESC); + assertThat(firstOrder.getProperty()).isEqualTo("sortProperty1"); + + Sort.Order secondOrder = orderList.get(1); + assertThat(secondOrder.getDirection()).isEqualTo(Sort.Direction.ASC); + assertThat(secondOrder.getProperty()).isEqualTo("sortProperty2"); + + } + @EnableFeignClients(clients = InvoiceClient.class) @LoadBalancerClient(name = "local", configuration = LocalClientConfiguration.class) @SpringBootApplication(scanBasePackages = "org.springframework.cloud.openfeign.encoding.app",