diff --git a/core/src/main/java/feign/Feign.java b/core/src/main/java/feign/Feign.java index 6962da64..492e384b 100644 --- a/core/src/main/java/feign/Feign.java +++ b/core/src/main/java/feign/Feign.java @@ -103,8 +103,8 @@ public abstract class Feign { private Client client = new Client.Default(null, null); private Retryer retryer = new Retryer.Default(); private Logger logger = new NoOpLogger(); - private Encoder encoder = new Encoder.Default(); - private Decoder decoder = new Decoder.Default(); + private Encoder encoder = new Encoder.Default(); + private Decoder decoder = new Decoder.Default(); private QueryMapEncoder queryMapEncoder = new FieldQueryMapEncoder(); private ErrorDecoder errorDecoder = new ErrorDecoder.Default(); private Options options = new Options(); @@ -141,12 +141,12 @@ public abstract class Feign { return this; } - public Builder encoder(Encoder encoder) { + public Builder encoder(Encoder encoder) { this.encoder = encoder; return this; } - public Builder decoder(Decoder decoder) { + public Builder decoder(Decoder decoder) { this.decoder = decoder; return this; } @@ -159,8 +159,8 @@ public abstract class Feign { /** * Allows to map the response before passing it to the decoder. */ - public Builder mapAndDecode(ResponseMapper mapper, Decoder decoder) { - this.decoder = new ResponseMappingDecoder(mapper, decoder); + public Builder mapAndDecode(ResponseMapper mapper, Decoder decoder) { + this.decoder = new ResponseMappingDecoder(mapper, decoder); return this; } @@ -277,8 +277,8 @@ public abstract class Feign { Logger logger = Capability.enrich(this.logger, capabilities); Contract contract = Capability.enrich(this.contract, capabilities); Options options = Capability.enrich(this.options, capabilities); - Encoder encoder = Capability.enrich(this.encoder, capabilities); - Decoder decoder = Capability.enrich(this.decoder, capabilities); + Encoder encoder = Capability.enrich(this.encoder, capabilities); + Decoder decoder = Capability.enrich(this.decoder, capabilities); InvocationHandlerFactory invocationHandlerFactory = Capability.enrich(this.invocationHandlerFactory, capabilities); QueryMapEncoder queryMapEncoder = Capability.enrich(this.queryMapEncoder, capabilities); @@ -293,18 +293,18 @@ public abstract class Feign { } } - public static class ResponseMappingDecoder implements Decoder { + public static class ResponseMappingDecoder implements Decoder { private final ResponseMapper mapper; - private final Decoder delegate; + private final Decoder delegate; - public ResponseMappingDecoder(ResponseMapper mapper, Decoder decoder) { + public ResponseMappingDecoder(ResponseMapper mapper, Decoder decoder) { this.mapper = mapper; this.delegate = decoder; } @Override - public Object decode(Response response, Type type) throws IOException { + public E decode(Response response, Type type) throws IOException { return delegate.decode(mapper.map(response, type), type); } } diff --git a/core/src/main/java/feign/codec/Decoder.java b/core/src/main/java/feign/codec/Decoder.java index 88968886..1d3129ed 100644 --- a/core/src/main/java/feign/codec/Decoder.java +++ b/core/src/main/java/feign/codec/Decoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -60,7 +60,7 @@ import feign.Util; * {@link DecodeException} unless they are a subclass of {@link FeignException} already, and unless * the client was configured with {@link Feign.Builder#decode404()}. */ -public interface Decoder { +public interface Decoder { /** * Decodes an http response into an object corresponding to its @@ -75,10 +75,12 @@ public interface Decoder { * @throws DecodeException when decoding failed due to a checked exception besides IOException. * @throws FeignException when decoding succeeds, but conveys the operation failed. */ - Object decode(Response response, Type type) throws IOException, DecodeException, FeignException; + E decode(Response response, Type type) throws IOException, DecodeException, FeignException; /** Default implementation of {@code Decoder}. */ - public class Default extends StringDecoder { + public class Default implements Decoder { + + private StringDecoder stringDecoder = new StringDecoder(); @Override public Object decode(Response response, Type type) throws IOException { @@ -89,7 +91,7 @@ public interface Decoder { if (byte[].class.equals(type)) { return Util.toByteArray(response.body().asInputStream()); } - return super.decode(response, type); + return stringDecoder.decode(response, type); } } } diff --git a/core/src/main/java/feign/codec/Encoder.java b/core/src/main/java/feign/codec/Encoder.java index c650774f..a87fb0ff 100644 --- a/core/src/main/java/feign/codec/Encoder.java +++ b/core/src/main/java/feign/codec/Encoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -63,7 +63,7 @@ import static java.lang.String.format; * Session login(@Param("username") String username, @Param("password") String password); * */ -public interface Encoder { +public interface Encoder { /** Type literal for {@code Map}, indicating the object to encode is a form. */ Type MAP_STRING_WILDCARD = Util.MAP_STRING_WILDCARD; @@ -76,12 +76,12 @@ public interface Encoder { * @param template the request template to populate. * @throws EncodeException when encoding failed due to a checked exception. */ - void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException; + void encode(E object, Type bodyType, RequestTemplate template) throws EncodeException; /** * Default implementation of {@code Encoder}. */ - class Default implements Encoder { + class Default implements Encoder { @Override public void encode(Object object, Type bodyType, RequestTemplate template) { diff --git a/core/src/main/java/feign/codec/StringDecoder.java b/core/src/main/java/feign/codec/StringDecoder.java index 2e6143f9..67cf943c 100644 --- a/core/src/main/java/feign/codec/StringDecoder.java +++ b/core/src/main/java/feign/codec/StringDecoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -19,10 +19,10 @@ import feign.Response; import feign.Util; import static java.lang.String.format; -public class StringDecoder implements Decoder { +public class StringDecoder implements Decoder { @Override - public Object decode(Response response, Type type) throws IOException { + public String decode(Response response, Type type) throws IOException { Response.Body body = response.body(); if (body == null) { return null; diff --git a/core/src/main/java/feign/optionals/OptionalDecoder.java b/core/src/main/java/feign/optionals/OptionalDecoder.java index 063c584d..2dfaaade 100644 --- a/core/src/main/java/feign/optionals/OptionalDecoder.java +++ b/core/src/main/java/feign/optionals/OptionalDecoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -22,19 +22,23 @@ import java.lang.reflect.Type; import java.util.Objects; import java.util.Optional; -public final class OptionalDecoder implements Decoder { - final Decoder delegate; +public final class OptionalDecoder implements Decoder { + final Decoder delegate; - public OptionalDecoder(Decoder delegate) { + public OptionalDecoder(Decoder delegate) { Objects.requireNonNull(delegate, "Decoder must not be null. "); this.delegate = delegate; } @Override - public Object decode(Response response, Type type) throws IOException { + public E decode(Response response, Type type) throws IOException { if (!isOptional(type)) { return delegate.decode(response, type); } + return (E) decodeOptional(response, type); + } + + private Optional decodeOptional(Response response, Type type) throws IOException { if (response.status() == 404 || response.status() == 204) { return Optional.empty(); } diff --git a/core/src/main/java/feign/stream/StreamDecoder.java b/core/src/main/java/feign/stream/StreamDecoder.java index 5d884f4a..a69c65af 100644 --- a/core/src/main/java/feign/stream/StreamDecoder.java +++ b/core/src/main/java/feign/stream/StreamDecoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -44,16 +44,16 @@ import static feign.Util.ensureClosed; * } * */ -public final class StreamDecoder implements Decoder { +public final class StreamDecoder implements Decoder> { - private final Decoder iteratorDecoder; + private final Decoder iteratorDecoder; - StreamDecoder(Decoder iteratorDecoder) { + StreamDecoder(Decoder iteratorDecoder) { this.iteratorDecoder = iteratorDecoder; } @Override - public Object decode(Response response, Type type) + public Stream decode(Response response, Type type) throws IOException, FeignException { if (!(type instanceof ParameterizedType)) { throw new IllegalArgumentException("StreamDecoder supports only stream: unknown " + type); @@ -62,7 +62,7 @@ public final class StreamDecoder implements Decoder { if (!Stream.class.equals(streamType.getRawType())) { throw new IllegalArgumentException("StreamDecoder supports only stream: unknown " + type); } - Iterator iterator = + Iterator iterator = (Iterator) iteratorDecoder.decode(response, new IteratorParameterizedType(streamType)); return StreamSupport.stream( @@ -76,8 +76,8 @@ public final class StreamDecoder implements Decoder { }); } - public static StreamDecoder create(Decoder iteratorDecoder) { - return new StreamDecoder(iteratorDecoder); + public static StreamDecoder create(Decoder iteratorDecoder) { + return new StreamDecoder<>(iteratorDecoder); } static final class IteratorParameterizedType implements ParameterizedType { diff --git a/core/src/test/java/feign/AlwaysEncodeBodyContractTest.java b/core/src/test/java/feign/AlwaysEncodeBodyContractTest.java index 9d692996..513920e6 100644 --- a/core/src/test/java/feign/AlwaysEncodeBodyContractTest.java +++ b/core/src/test/java/feign/AlwaysEncodeBodyContractTest.java @@ -56,7 +56,7 @@ public class AlwaysEncodeBodyContractTest { String concatenate(String word1); } - private static class AllParametersSampleEncoder implements Encoder { + private static class AllParametersSampleEncoder implements Encoder { @Override public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException { @@ -67,7 +67,7 @@ public class AlwaysEncodeBodyContractTest { } } - private static class BodyParameterSampleEncoder implements Encoder { + private static class BodyParameterSampleEncoder implements Encoder { @Override public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException { diff --git a/core/src/test/java/feign/FeignTest.java b/core/src/test/java/feign/FeignTest.java index 8aa94a35..fbcdfe28 100644 --- a/core/src/test/java/feign/FeignTest.java +++ b/core/src/test/java/feign/FeignTest.java @@ -480,7 +480,7 @@ public class FeignTest { TestInterface api = new TestInterfaceBuilder() .decoder(new StringDecoder() { @Override - public Object decode(Response response, Type type) throws IOException { + public String decode(Response response, Type type) throws IOException { String string = super.decode(response, type).toString(); if ("retry!".equals(string)) { throw new RetryableException(response.status(), string, HttpMethod.POST, null, diff --git a/core/src/test/java/feign/UtilTest.java b/core/src/test/java/feign/UtilTest.java index d9e6b49e..78ee988f 100644 --- a/core/src/test/java/feign/UtilTest.java +++ b/core/src/test/java/feign/UtilTest.java @@ -298,7 +298,7 @@ public class UtilTest { ParameterizedDecoder PARAMETERIZED_DECODER_UNBOUND = null; } - interface ParameterizedDecoder> extends Decoder { + interface ParameterizedDecoder> extends Decoder { } diff --git a/core/src/test/java/feign/examples/GitHubExample.java b/core/src/test/java/feign/examples/GitHubExample.java index a0af9ae8..228b8f2a 100644 --- a/core/src/test/java/feign/examples/GitHubExample.java +++ b/core/src/test/java/feign/examples/GitHubExample.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -62,7 +62,7 @@ public class GitHubExample { /** * Here's how it looks to write a decoder. Note: you can instead use {@code feign-gson}! */ - static class GsonDecoder implements Decoder { + static class GsonDecoder implements Decoder { private final Gson gson = new Gson(); diff --git a/dropwizard-metrics4/src/main/java/feign/metrics4/MeteredDecoder.java b/dropwizard-metrics4/src/main/java/feign/metrics4/MeteredDecoder.java index 8f34f2db..78ec3a49 100644 --- a/dropwizard-metrics4/src/main/java/feign/metrics4/MeteredDecoder.java +++ b/dropwizard-metrics4/src/main/java/feign/metrics4/MeteredDecoder.java @@ -27,14 +27,14 @@ import feign.codec.Decoder; /** * Warp feign {@link Decoder} with metrics. */ -public class MeteredDecoder implements Decoder { +public class MeteredDecoder implements Decoder { - private final Decoder decoder; + private final Decoder decoder; private final MetricRegistry metricRegistry; private final MetricSuppliers metricSuppliers; private final FeignMetricName metricName; - public MeteredDecoder(Decoder decoder, MetricRegistry metricRegistry, + public MeteredDecoder(Decoder decoder, MetricRegistry metricRegistry, MetricSuppliers metricSuppliers) { this.decoder = decoder; this.metricRegistry = metricRegistry; @@ -43,7 +43,7 @@ public class MeteredDecoder implements Decoder { } @Override - public Object decode(Response response, Type type) + public E decode(Response response, Type type) throws IOException, DecodeException, FeignException { final RequestTemplate template = response.request().requestTemplate(); final MeteredBody body = response.body() == null @@ -52,7 +52,7 @@ public class MeteredDecoder implements Decoder { response = response.toBuilder().body(body).build(); - final Object decoded; + final E decoded; try (final Timer.Context classTimer = metricRegistry .timer( diff --git a/dropwizard-metrics4/src/main/java/feign/metrics4/MeteredEncoder.java b/dropwizard-metrics4/src/main/java/feign/metrics4/MeteredEncoder.java index 3b8f014f..a3ca39ce 100644 --- a/dropwizard-metrics4/src/main/java/feign/metrics4/MeteredEncoder.java +++ b/dropwizard-metrics4/src/main/java/feign/metrics4/MeteredEncoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -24,14 +24,14 @@ import feign.codec.Encoder; /** * Warp feign {@link Encoder} with metrics. */ -public class MeteredEncoder implements Encoder { +public class MeteredEncoder implements Encoder { - private final Encoder encoder; + private final Encoder encoder; private final MetricRegistry metricRegistry; private final MetricSuppliers metricSuppliers; private final FeignMetricName metricName; - public MeteredEncoder(Encoder encoder, MetricRegistry metricRegistry, + public MeteredEncoder(Encoder encoder, MetricRegistry metricRegistry, MetricSuppliers metricSuppliers) { this.encoder = encoder; this.metricRegistry = metricRegistry; @@ -40,7 +40,7 @@ public class MeteredEncoder implements Encoder { } @Override - public void encode(Object object, Type bodyType, RequestTemplate template) + public void encode(E object, Type bodyType, RequestTemplate template) throws EncodeException { try (final Timer.Context classTimer = metricRegistry.timer( diff --git a/dropwizard-metrics5/src/main/java/feign/metrics5/MeteredDecoder.java b/dropwizard-metrics5/src/main/java/feign/metrics5/MeteredDecoder.java index 828142a1..02c25225 100644 --- a/dropwizard-metrics5/src/main/java/feign/metrics5/MeteredDecoder.java +++ b/dropwizard-metrics5/src/main/java/feign/metrics5/MeteredDecoder.java @@ -25,16 +25,16 @@ import io.dropwizard.metrics5.MetricRegistry; import io.dropwizard.metrics5.Timer.Context; /** - * Warp feign {@link Decoder} with metrics. + * Warp feign {@link Decoder} with metrics. */ -public class MeteredDecoder implements Decoder { +public class MeteredDecoder implements Decoder { - private final Decoder decoder; + private final Decoder decoder; private final MetricRegistry metricRegistry; private final MetricSuppliers metricSuppliers; private final FeignMetricName metricName; - public MeteredDecoder(Decoder decoder, MetricRegistry metricRegistry, + public MeteredDecoder(Decoder decoder, MetricRegistry metricRegistry, MetricSuppliers metricSuppliers) { this.decoder = decoder; this.metricRegistry = metricRegistry; @@ -43,7 +43,7 @@ public class MeteredDecoder implements Decoder { } @Override - public Object decode(Response response, Type type) + public E decode(Response response, Type type) throws IOException, DecodeException, FeignException { final RequestTemplate template = response.request().requestTemplate(); final MeteredBody body = response.body() == null @@ -52,7 +52,7 @@ public class MeteredDecoder implements Decoder { response = response.toBuilder().body(body).build(); - final Object decoded; + final E decoded; try (final Context classTimer = metricRegistry .timer(metricName.metricName(template.methodMetadata(), template.feignTarget()) diff --git a/dropwizard-metrics5/src/main/java/feign/metrics5/MeteredEncoder.java b/dropwizard-metrics5/src/main/java/feign/metrics5/MeteredEncoder.java index 6a59176f..bc08265a 100644 --- a/dropwizard-metrics5/src/main/java/feign/metrics5/MeteredEncoder.java +++ b/dropwizard-metrics5/src/main/java/feign/metrics5/MeteredEncoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -24,14 +24,14 @@ import io.dropwizard.metrics5.Timer.Context; /** * Warp feign {@link Encoder} with metrics. */ -public class MeteredEncoder implements Encoder { +public class MeteredEncoder implements Encoder { - private final Encoder encoder; + private final Encoder encoder; private final MetricRegistry metricRegistry; private final MetricSuppliers metricSuppliers; private final FeignMetricName metricName; - public MeteredEncoder(Encoder encoder, MetricRegistry metricRegistry, + public MeteredEncoder(Encoder encoder, MetricRegistry metricRegistry, MetricSuppliers metricSuppliers) { this.encoder = encoder; this.metricRegistry = metricRegistry; @@ -40,7 +40,7 @@ public class MeteredEncoder implements Encoder { } @Override - public void encode(Object object, Type bodyType, RequestTemplate template) + public void encode(E object, Type bodyType, RequestTemplate template) throws EncodeException { try (final Context classTimer = metricRegistry.timer( diff --git a/gson/src/main/java/feign/gson/GsonDecoder.java b/gson/src/main/java/feign/gson/GsonDecoder.java index 3b7a6d68..abd90272 100644 --- a/gson/src/main/java/feign/gson/GsonDecoder.java +++ b/gson/src/main/java/feign/gson/GsonDecoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -25,7 +25,7 @@ import feign.codec.Decoder; import static feign.Util.UTF_8; import static feign.Util.ensureClosed; -public class GsonDecoder implements Decoder { +public class GsonDecoder implements Decoder { private final Gson gson; diff --git a/gson/src/main/java/feign/gson/GsonEncoder.java b/gson/src/main/java/feign/gson/GsonEncoder.java index efe90395..33b899c8 100644 --- a/gson/src/main/java/feign/gson/GsonEncoder.java +++ b/gson/src/main/java/feign/gson/GsonEncoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -20,7 +20,7 @@ import java.util.Collections; import feign.RequestTemplate; import feign.codec.Encoder; -public class GsonEncoder implements Encoder { +public class GsonEncoder implements Encoder { private final Gson gson; diff --git a/jackson-jaxb/src/main/java/feign/jackson/jaxb/JacksonJaxbJsonDecoder.java b/jackson-jaxb/src/main/java/feign/jackson/jaxb/JacksonJaxbJsonDecoder.java index 9fbda3e9..28b8768b 100644 --- a/jackson-jaxb/src/main/java/feign/jackson/jaxb/JacksonJaxbJsonDecoder.java +++ b/jackson-jaxb/src/main/java/feign/jackson/jaxb/JacksonJaxbJsonDecoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -23,7 +23,7 @@ import feign.codec.Decoder; import static com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS; import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; -public final class JacksonJaxbJsonDecoder implements Decoder { +public final class JacksonJaxbJsonDecoder implements Decoder { private final JacksonJaxbJsonProvider jacksonJaxbJsonProvider; public JacksonJaxbJsonDecoder() { diff --git a/jackson-jaxb/src/main/java/feign/jackson/jaxb/JacksonJaxbJsonEncoder.java b/jackson-jaxb/src/main/java/feign/jackson/jaxb/JacksonJaxbJsonEncoder.java index 16d01562..8b9c6ea1 100644 --- a/jackson-jaxb/src/main/java/feign/jackson/jaxb/JacksonJaxbJsonEncoder.java +++ b/jackson-jaxb/src/main/java/feign/jackson/jaxb/JacksonJaxbJsonEncoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -25,7 +25,7 @@ import feign.codec.Encoder; import static com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS; import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; -public final class JacksonJaxbJsonEncoder implements Encoder { +public final class JacksonJaxbJsonEncoder implements Encoder { private final JacksonJaxbJsonProvider jacksonJaxbJsonProvider; public JacksonJaxbJsonEncoder() { diff --git a/jackson-jr/src/main/java/feign/jackson/jr/JacksonJrDecoder.java b/jackson-jr/src/main/java/feign/jackson/jr/JacksonJrDecoder.java index bb0f3e99..f9483dae 100644 --- a/jackson-jr/src/main/java/feign/jackson/jr/JacksonJrDecoder.java +++ b/jackson-jr/src/main/java/feign/jackson/jr/JacksonJrDecoder.java @@ -30,7 +30,7 @@ import java.util.Map; /** * A {@link Decoder} that uses Jackson Jr to convert objects to String or byte representation. */ -public class JacksonJrDecoder extends JacksonJrMapper implements Decoder { +public class JacksonJrDecoder extends JacksonJrMapper implements Decoder { @FunctionalInterface interface Transformer { diff --git a/jackson/src/main/java/feign/jackson/JacksonDecoder.java b/jackson/src/main/java/feign/jackson/JacksonDecoder.java index 6b24843d..e36a1412 100644 --- a/jackson/src/main/java/feign/jackson/JacksonDecoder.java +++ b/jackson/src/main/java/feign/jackson/JacksonDecoder.java @@ -28,7 +28,7 @@ import feign.Response; import feign.Util; import feign.codec.Decoder; -public class JacksonDecoder implements Decoder { +public class JacksonDecoder implements Decoder { private final ObjectMapper mapper; diff --git a/jackson/src/main/java/feign/jackson/JacksonEncoder.java b/jackson/src/main/java/feign/jackson/JacksonEncoder.java index 4298d8a6..3d27f268 100644 --- a/jackson/src/main/java/feign/jackson/JacksonEncoder.java +++ b/jackson/src/main/java/feign/jackson/JacksonEncoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -26,7 +26,7 @@ import feign.codec.EncodeException; import feign.codec.Encoder; import feign.Util; -public class JacksonEncoder implements Encoder { +public class JacksonEncoder implements Encoder { private final ObjectMapper mapper; diff --git a/jackson/src/main/java/feign/jackson/JacksonIteratorDecoder.java b/jackson/src/main/java/feign/jackson/JacksonIteratorDecoder.java index 22133dde..002be343 100644 --- a/jackson/src/main/java/feign/jackson/JacksonIteratorDecoder.java +++ b/jackson/src/main/java/feign/jackson/JacksonIteratorDecoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -54,7 +54,7 @@ import static feign.Util.ensureClosed; * } * */ -public final class JacksonIteratorDecoder implements Decoder { +public final class JacksonIteratorDecoder implements Decoder { private final ObjectMapper mapper; diff --git a/jaxb/src/main/java/feign/jaxb/JAXBDecoder.java b/jaxb/src/main/java/feign/jaxb/JAXBDecoder.java index b8d49c11..4ab7d152 100644 --- a/jaxb/src/main/java/feign/jaxb/JAXBDecoder.java +++ b/jaxb/src/main/java/feign/jaxb/JAXBDecoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -47,7 +47,7 @@ import org.xml.sax.SAXException; * The JAXBContextFactory should be reused across requests as it caches the created JAXB contexts. *

*/ -public class JAXBDecoder implements Decoder { +public class JAXBDecoder implements Decoder { private final JAXBContextFactory jaxbContextFactory; private final boolean namespaceAware; diff --git a/jaxb/src/main/java/feign/jaxb/JAXBEncoder.java b/jaxb/src/main/java/feign/jaxb/JAXBEncoder.java index 78af26d8..99e9a0f5 100644 --- a/jaxb/src/main/java/feign/jaxb/JAXBEncoder.java +++ b/jaxb/src/main/java/feign/jaxb/JAXBEncoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -41,7 +41,7 @@ import feign.codec.Encoder; * The JAXBContextFactory should be reused across requests as it caches the created JAXB contexts. *

*/ -public class JAXBEncoder implements Encoder { +public class JAXBEncoder implements Encoder { private final JAXBContextFactory jaxbContextFactory; diff --git a/json/src/main/java/feign/json/JsonDecoder.java b/json/src/main/java/feign/json/JsonDecoder.java index 578ae3ea..b5d21468 100644 --- a/json/src/main/java/feign/json/JsonDecoder.java +++ b/json/src/main/java/feign/json/JsonDecoder.java @@ -49,7 +49,7 @@ import static java.lang.String.format; * System.out.println(contributors.getJSONObject(0).getString("login")); * */ -public class JsonDecoder implements Decoder { +public class JsonDecoder implements Decoder { @Override public Object decode(Response response, Type type) throws IOException, DecodeException { diff --git a/json/src/main/java/feign/json/JsonEncoder.java b/json/src/main/java/feign/json/JsonEncoder.java index b809f196..f85e2941 100644 --- a/json/src/main/java/feign/json/JsonEncoder.java +++ b/json/src/main/java/feign/json/JsonEncoder.java @@ -48,7 +48,7 @@ import static java.lang.String.format; * github.create("openfeign", "feign", contributor); * */ -public class JsonEncoder implements Encoder { +public class JsonEncoder implements Encoder { @Override public void encode(Object object, Type bodyType, RequestTemplate template) diff --git a/micrometer/src/main/java/feign/micrometer/MeteredDecoder.java b/micrometer/src/main/java/feign/micrometer/MeteredDecoder.java index c47e5baa..76edce11 100644 --- a/micrometer/src/main/java/feign/micrometer/MeteredDecoder.java +++ b/micrometer/src/main/java/feign/micrometer/MeteredDecoder.java @@ -25,20 +25,20 @@ import java.util.Optional; import static feign.micrometer.MetricTagResolver.EMPTY_TAGS_ARRAY; /** - * Warp feign {@link Decoder} with metrics. + * Warp feign {@link Decoder} with metrics. */ -public class MeteredDecoder implements Decoder { +public class MeteredDecoder implements Decoder { - private final Decoder decoder; + private final Decoder decoder; private final MeterRegistry meterRegistry; private final MetricName metricName; private final MetricTagResolver metricTagResolver; - public MeteredDecoder(Decoder decoder, MeterRegistry meterRegistry) { + public MeteredDecoder(Decoder decoder, MeterRegistry meterRegistry) { this(decoder, meterRegistry, new FeignMetricName(Decoder.class), new FeignMetricTagResolver()); } - public MeteredDecoder(Decoder decoder, MeterRegistry meterRegistry, MetricName metricName, + public MeteredDecoder(Decoder decoder, MeterRegistry meterRegistry, MetricName metricName, MetricTagResolver metricTagResolver) { this.decoder = decoder; this.meterRegistry = meterRegistry; @@ -47,7 +47,7 @@ public class MeteredDecoder implements Decoder { } @Override - public Object decode(Response response, Type type) + public E decode(Response response, Type type) throws IOException, FeignException { final Optional body = Optional.ofNullable(response.body()) .map(MeteredBody::new); @@ -55,7 +55,7 @@ public class MeteredDecoder implements Decoder { Response meteredResponse = body.map(b -> response.toBuilder().body(b).build()) .orElse(response); - Object decoded; + E decoded; final Timer.Sample sample = Timer.start(meterRegistry); Timer timer = null; diff --git a/micrometer/src/main/java/feign/micrometer/MeteredEncoder.java b/micrometer/src/main/java/feign/micrometer/MeteredEncoder.java index 4437ba27..801a1426 100644 --- a/micrometer/src/main/java/feign/micrometer/MeteredEncoder.java +++ b/micrometer/src/main/java/feign/micrometer/MeteredEncoder.java @@ -23,18 +23,18 @@ import static feign.micrometer.MetricTagResolver.EMPTY_TAGS_ARRAY; /** * Warp feign {@link Encoder} with metrics. */ -public class MeteredEncoder implements Encoder { +public class MeteredEncoder implements Encoder { - private final Encoder encoder; + private final Encoder encoder; private final MeterRegistry meterRegistry; private final MetricName metricName; private final MetricTagResolver metricTagResolver; - public MeteredEncoder(Encoder encoder, MeterRegistry meterRegistry) { + public MeteredEncoder(Encoder encoder, MeterRegistry meterRegistry) { this(encoder, meterRegistry, new FeignMetricName(Encoder.class), new FeignMetricTagResolver()); } - public MeteredEncoder(Encoder encoder, + public MeteredEncoder(Encoder encoder, MeterRegistry meterRegistry, MetricName metricName, MetricTagResolver metricTagResolver) { @@ -45,7 +45,7 @@ public class MeteredEncoder implements Encoder { } @Override - public void encode(Object object, Type bodyType, RequestTemplate template) + public void encode(E object, Type bodyType, RequestTemplate template) throws EncodeException { createTimer(object, bodyType, template) .record(() -> encoder.encode(object, bodyType, template)); diff --git a/mock/src/test/java/feign/mock/MockClientSequentialTest.java b/mock/src/test/java/feign/mock/MockClientSequentialTest.java index e3f4324e..6e44c7ba 100644 --- a/mock/src/test/java/feign/mock/MockClientSequentialTest.java +++ b/mock/src/test/java/feign/mock/MockClientSequentialTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -72,16 +72,16 @@ public class MockClientSequentialTest { } - class AssertionDecoder implements Decoder { + class AssertionDecoder implements Decoder { - private final Decoder delegate; + private final Decoder delegate; - public AssertionDecoder(Decoder delegate) { + public AssertionDecoder(Decoder delegate) { this.delegate = delegate; } @Override - public Object decode(Response response, Type type) + public E decode(Response response, Type type) throws IOException, DecodeException, FeignException { assertThat(response.request(), notNullValue()); @@ -102,7 +102,7 @@ public class MockClientSequentialTest { .add("Name", "netflix") .build(); mockClientSequential = new MockClient(true); - githubSequential = Feign.builder().decoder(new AssertionDecoder(new GsonDecoder())) + githubSequential = Feign.builder().decoder(new AssertionDecoder<>(new GsonDecoder())) .client(mockClientSequential .add(RequestKey .builder(HttpMethod.GET, "/repos/netflix/feign/contributors") diff --git a/mock/src/test/java/feign/mock/MockClientTest.java b/mock/src/test/java/feign/mock/MockClientTest.java index 3ea208ee..562aa03f 100644 --- a/mock/src/test/java/feign/mock/MockClientTest.java +++ b/mock/src/test/java/feign/mock/MockClientTest.java @@ -68,16 +68,16 @@ public class MockClientTest { } - class AssertionDecoder implements Decoder { + class AssertionDecoder implements Decoder { - private final Decoder delegate; + private final Decoder delegate; - public AssertionDecoder(Decoder delegate) { + public AssertionDecoder(Decoder delegate) { this.delegate = delegate; } @Override - public Object decode(Response response, Type type) + public E decode(Response response, Type type) throws IOException, DecodeException, FeignException { assertThat(response.request(), notNullValue()); @@ -103,7 +103,7 @@ public class MockClientTest { .body("{\"login\":\"velo_at_github\",\"type\":\"preposterous hacker\"}") .build(); mockClient = new MockClient(); - github = Feign.builder().decoder(new AssertionDecoder(new GsonDecoder())) + github = Feign.builder().decoder(new AssertionDecoder<>(new GsonDecoder())) .client(mockClient.ok(HttpMethod.GET, "/repos/netflix/feign/contributors", data) .ok(HttpMethod.GET, "/repos/netflix/feign/contributors?client_id=55") .ok(HttpMethod.GET, "/repos/netflix/feign/contributors?client_id=7 7", diff --git a/sax/src/main/java/feign/sax/SAXDecoder.java b/sax/src/main/java/feign/sax/SAXDecoder.java index 98193fd9..348c9950 100644 --- a/sax/src/main/java/feign/sax/SAXDecoder.java +++ b/sax/src/main/java/feign/sax/SAXDecoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign 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 @@ -46,7 +46,7 @@ import static feign.Util.resolveLastTypeParameter; * .target(MyApi.class, "http://api"); * */ -public class SAXDecoder implements Decoder { +public class SAXDecoder implements Decoder { private final Map> handlerFactories; diff --git a/soap/src/main/java/feign/soap/SOAPDecoder.java b/soap/src/main/java/feign/soap/SOAPDecoder.java index 426bd31b..abbad30a 100644 --- a/soap/src/main/java/feign/soap/SOAPDecoder.java +++ b/soap/src/main/java/feign/soap/SOAPDecoder.java @@ -81,7 +81,7 @@ import feign.jaxb.JAXBContextFactory; * @see SOAPErrorDecoder * @see SOAPFaultException */ -public class SOAPDecoder implements Decoder { +public class SOAPDecoder implements Decoder { private final JAXBContextFactory jaxbContextFactory; diff --git a/soap/src/main/java/feign/soap/SOAPEncoder.java b/soap/src/main/java/feign/soap/SOAPEncoder.java index 5263324b..f7096a37 100644 --- a/soap/src/main/java/feign/soap/SOAPEncoder.java +++ b/soap/src/main/java/feign/soap/SOAPEncoder.java @@ -83,7 +83,7 @@ import feign.jaxb.JAXBContextFactory; * The JAXBContextFactory should be reused across requests as it caches the created JAXB contexts. *

*/ -public class SOAPEncoder implements Encoder { +public class SOAPEncoder implements Encoder { private static final String DEFAULT_SOAP_PROTOCOL = SOAPConstants.SOAP_1_1_PROTOCOL;