diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsConfiguration.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsConfiguration.java index 97fb278a..8ced1274 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsConfiguration.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsConfiguration.java @@ -85,7 +85,7 @@ public class FeignClientsConfiguration { @ConditionalOnMissingBean public Decoder feignDecoder() { return new OptionalDecoder( - new ResponseEntityDecoder(new SpringDecoder(this.messageConverters))); + new ResponseEntityDecoder(new SpringDecoder(this.messageConverters))); } @Bean @@ -99,17 +99,17 @@ public class FeignClientsConfiguration { @ConditionalOnClass(name = "org.springframework.data.domain.Pageable") @ConditionalOnMissingBean public Encoder feignEncoderPageable( - ObjectProvider formWriterProvider) { + ObjectProvider formWriterProvider) { PageableSpringEncoder encoder = new PageableSpringEncoder( - springEncoder(formWriterProvider)); + springEncoder(formWriterProvider)); if (springDataWebProperties != null) { encoder.setPageParameter( - springDataWebProperties.getPageable().getPageParameter()); + springDataWebProperties.getPageable().getPageParameter()); encoder.setSizeParameter( - springDataWebProperties.getPageable().getSizeParameter()); + springDataWebProperties.getPageable().getSizeParameter()); encoder.setSortParameter( - springDataWebProperties.getSort().getSortParameter()); + springDataWebProperties.getSort().getSortParameter()); } return encoder; } @@ -165,7 +165,7 @@ public class FeignClientsConfiguration { if (formWriter != null) { return new SpringEncoder(new SpringPojoFormEncoder(formWriter), - this.messageConverters); + this.messageConverters); } else { return new SpringEncoder(new SpringFormEncoder(), this.messageConverters); @@ -192,7 +192,7 @@ public class FeignClientsConfiguration { super(); MultipartFormContentProcessor processor = (MultipartFormContentProcessor) getContentProcessor( - MULTIPART); + MULTIPART); processor.addFirstWriter(formWriter); } diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PageJacksonModule.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PageJacksonModule.java index 255e3872..ac6c0c8c 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PageJacksonModule.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PageJacksonModule.java @@ -64,8 +64,9 @@ public class PageJacksonModule extends Module { private final Page delegate; SimplePageImpl(@JsonProperty("content") List content, - @JsonProperty("number") int number, @JsonProperty("size") int size, - @JsonProperty("totalElements") long totalElements, @JsonProperty("sort") Sort sort) { + @JsonProperty("number") int number, @JsonProperty("size") int size, + @JsonProperty("totalElements") long totalElements, + @JsonProperty("sort") Sort sort) { PageRequest pageRequest; if (sort != null) { pageRequest = PageRequest.of(number, size, sort); diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SortJacksonModule.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SortJacksonModule.java index e70857b5..3b2ce147 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SortJacksonModule.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SortJacksonModule.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.cloud.openfeign.support; import com.fasterxml.jackson.core.Version; @@ -8,10 +24,13 @@ import com.fasterxml.jackson.databind.module.SimpleSerializers; import org.springframework.data.domain.Sort; /** - * This jackson module provides support to add serialize and deserialize for spring {@link Sort} object. + * This jackson module provides support to add serialize and deserialize for spring + * {@link Sort} object. + * * @author canbezmen */ public class SortJacksonModule extends Module { + @Override public String getModuleName() { return "SortModule"; @@ -29,7 +48,9 @@ public class SortJacksonModule extends Module { context.addSerializers(serializers); SimpleDeserializers deserializers = new SimpleDeserializers(); - deserializers.addDeserializer(Sort.class, new SortJsonComponent.SortDeserializer()); + deserializers.addDeserializer(Sort.class, + new SortJsonComponent.SortDeserializer()); context.addDeserializers(deserializers); } + } diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SortJsonComponent.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SortJsonComponent.java index 64bc6813..a45b178d 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SortJsonComponent.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SortJsonComponent.java @@ -34,6 +34,7 @@ import org.springframework.data.domain.Sort; /** * This class provides support to serialize and deserialize spring {@link Sort} object. + * * @author canbezmen */ public class SortJsonComponent { @@ -41,7 +42,8 @@ public class SortJsonComponent { public static class SortSerializer extends JsonSerializer { @Override - public void serialize(Sort value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + public void serialize(Sort value, JsonGenerator gen, + SerializerProvider serializers) throws IOException { gen.writeStartArray(); value.iterator().forEachRemaining(v -> { try { @@ -64,14 +66,16 @@ public class SortJsonComponent { public static class SortDeserializer extends JsonDeserializer { @Override - public Sort deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { + public Sort deserialize(JsonParser jsonParser, + DeserializationContext deserializationContext) throws IOException { TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser); if (treeNode.isArray()) { ArrayNode arrayNode = (ArrayNode) treeNode; List orders = new ArrayList<>(); for (JsonNode jsonNode : arrayNode) { - Sort.Order order = new Sort.Order(Sort.Direction - .valueOf(jsonNode.get("direction").textValue()), jsonNode.get("property").textValue()); + Sort.Order order = new Sort.Order( + Sort.Direction.valueOf(jsonNode.get("direction").textValue()), + jsonNode.get("property").textValue()); orders.add(order); } return Sort.by(orders); @@ -85,4 +89,5 @@ public class SortJsonComponent { } } + } 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 524bb550..c909eede 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 @@ -17,12 +17,11 @@ package org.springframework.cloud.openfeign.encoding; import java.util.Collections; +import java.util.Optional; import com.netflix.loadbalancer.BaseLoadBalancer; import com.netflix.loadbalancer.ILoadBalancer; import com.netflix.loadbalancer.Server; -import java.util.Optional; - import org.junit.Test; import org.junit.runner.RunWith; @@ -84,8 +83,8 @@ public class FeignPageableEncodingTests { assertThat(response.getBody()).isNotNull(); assertThat(pageable.getPageSize()).isEqualTo(response.getBody().getSize()); assertThat(response.getBody().getPageable().getSort()).hasSize(1); - Optional optionalOrder = response.getBody().getPageable().getSort().get() - .findFirst(); + Optional optionalOrder = response.getBody().getPageable().getSort() + .get().findFirst(); if (optionalOrder.isPresent()) { Sort.Order order = optionalOrder.get(); assertThat(order.getDirection()).isEqualTo(Sort.Direction.ASC); diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SortJacksonModuleTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SortJacksonModuleTests.java index 27f0c92b..12d09890 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SortJacksonModuleTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SortJacksonModuleTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.cloud.openfeign.support; import java.util.Optional; @@ -41,7 +57,7 @@ class SortJacksonModuleTests { assertThat(result.getPageable().getPageNumber()).isEqualTo(1); assertThat(result.getPageable().getSort()).hasSize(1); Optional optionalOrder = result.getPageable().getSort().get() - .findFirst(); + .findFirst(); if (optionalOrder.isPresent()) { Sort.Order order = optionalOrder.get(); assertThat(order.getDirection()).isEqualTo(Sort.Direction.ASC);