Checkstyle bug for license fixed.

This commit is contained in:
Can Bezmen
2020-04-28 20:44:27 +03:00
parent 525bb603f7
commit b538d7f88c
6 changed files with 63 additions and 21 deletions

View File

@@ -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<AbstractFormWriter> formWriterProvider) {
ObjectProvider<AbstractFormWriter> 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);
}

View File

@@ -64,8 +64,9 @@ public class PageJacksonModule extends Module {
private final Page<T> delegate;
SimplePageImpl(@JsonProperty("content") List<T> 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);

View File

@@ -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);
}
}

View File

@@ -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<Sort> {
@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<Sort> {
@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<Sort.Order> 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 {
}
}
}

View File

@@ -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<Sort.Order> optionalOrder = response.getBody().getPageable().getSort().get()
.findFirst();
Optional<Sort.Order> optionalOrder = response.getBody().getPageable().getSort()
.get().findFirst();
if (optionalOrder.isPresent()) {
Sort.Order order = optionalOrder.get();
assertThat(order.getDirection()).isEqualTo(Sort.Direction.ASC);

View File

@@ -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<Sort.Order> optionalOrder = result.getPageable().getSort().get()
.findFirst();
.findFirst();
if (optionalOrder.isPresent()) {
Sort.Order order = optionalOrder.get();
assertThat(order.getDirection()).isEqualTo(Sort.Direction.ASC);