Browse Source

Include generics on codecs

pull/1521/head
Marvin Froeder 3 years ago
parent
commit
2eb87e12ba
  1. 24
      core/src/main/java/feign/Feign.java
  2. 12
      core/src/main/java/feign/codec/Decoder.java
  3. 8
      core/src/main/java/feign/codec/Encoder.java
  4. 6
      core/src/main/java/feign/codec/StringDecoder.java
  5. 14
      core/src/main/java/feign/optionals/OptionalDecoder.java
  6. 16
      core/src/main/java/feign/stream/StreamDecoder.java
  7. 4
      core/src/test/java/feign/AlwaysEncodeBodyContractTest.java
  8. 2
      core/src/test/java/feign/FeignTest.java
  9. 2
      core/src/test/java/feign/UtilTest.java
  10. 4
      core/src/test/java/feign/examples/GitHubExample.java
  11. 10
      dropwizard-metrics4/src/main/java/feign/metrics4/MeteredDecoder.java
  12. 10
      dropwizard-metrics4/src/main/java/feign/metrics4/MeteredEncoder.java
  13. 12
      dropwizard-metrics5/src/main/java/feign/metrics5/MeteredDecoder.java
  14. 10
      dropwizard-metrics5/src/main/java/feign/metrics5/MeteredEncoder.java
  15. 4
      gson/src/main/java/feign/gson/GsonDecoder.java
  16. 4
      gson/src/main/java/feign/gson/GsonEncoder.java
  17. 4
      jackson-jaxb/src/main/java/feign/jackson/jaxb/JacksonJaxbJsonDecoder.java
  18. 4
      jackson-jaxb/src/main/java/feign/jackson/jaxb/JacksonJaxbJsonEncoder.java
  19. 2
      jackson-jr/src/main/java/feign/jackson/jr/JacksonJrDecoder.java
  20. 2
      jackson/src/main/java/feign/jackson/JacksonDecoder.java
  21. 4
      jackson/src/main/java/feign/jackson/JacksonEncoder.java
  22. 4
      jackson/src/main/java/feign/jackson/JacksonIteratorDecoder.java
  23. 4
      jaxb/src/main/java/feign/jaxb/JAXBDecoder.java
  24. 4
      jaxb/src/main/java/feign/jaxb/JAXBEncoder.java
  25. 2
      json/src/main/java/feign/json/JsonDecoder.java
  26. 2
      json/src/main/java/feign/json/JsonEncoder.java
  27. 14
      micrometer/src/main/java/feign/micrometer/MeteredDecoder.java
  28. 10
      micrometer/src/main/java/feign/micrometer/MeteredEncoder.java
  29. 12
      mock/src/test/java/feign/mock/MockClientSequentialTest.java
  30. 10
      mock/src/test/java/feign/mock/MockClientTest.java
  31. 4
      sax/src/main/java/feign/sax/SAXDecoder.java
  32. 2
      soap/src/main/java/feign/soap/SOAPDecoder.java
  33. 2
      soap/src/main/java/feign/soap/SOAPEncoder.java

24
core/src/main/java/feign/Feign.java

@ -103,8 +103,8 @@ public abstract class Feign { @@ -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 { @@ -141,12 +141,12 @@ public abstract class Feign {
return this;
}
public Builder encoder(Encoder encoder) {
public <E> Builder encoder(Encoder<E> encoder) {
this.encoder = encoder;
return this;
}
public Builder decoder(Decoder decoder) {
public <E> Builder decoder(Decoder<E> decoder) {
this.decoder = decoder;
return this;
}
@ -159,8 +159,8 @@ public abstract class Feign { @@ -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 <E> Builder mapAndDecode(ResponseMapper mapper, Decoder<E> decoder) {
this.decoder = new ResponseMappingDecoder<E>(mapper, decoder);
return this;
}
@ -277,8 +277,8 @@ public abstract class Feign { @@ -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 { @@ -293,18 +293,18 @@ public abstract class Feign {
}
}
public static class ResponseMappingDecoder implements Decoder {
public static class ResponseMappingDecoder<E> implements Decoder<E> {
private final ResponseMapper mapper;
private final Decoder delegate;
private final Decoder<E> delegate;
public ResponseMappingDecoder(ResponseMapper mapper, Decoder decoder) {
public ResponseMappingDecoder(ResponseMapper mapper, Decoder<E> 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);
}
}

12
core/src/main/java/feign/codec/Decoder.java

@ -1,5 +1,5 @@ @@ -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; @@ -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<E> {
/**
* Decodes an http response into an object corresponding to its
@ -75,10 +75,12 @@ public interface Decoder { @@ -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<Object> {
private StringDecoder stringDecoder = new StringDecoder();
@Override
public Object decode(Response response, Type type) throws IOException {
@ -89,7 +91,7 @@ public interface Decoder { @@ -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);
}
}
}

8
core/src/main/java/feign/codec/Encoder.java

@ -1,5 +1,5 @@ @@ -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; @@ -63,7 +63,7 @@ import static java.lang.String.format;
* Session login(@Param(&quot;username&quot;) String username, @Param(&quot;password&quot;) String password);
* </pre>
*/
public interface Encoder {
public interface Encoder<E> {
/** Type literal for {@code Map<String, ?>}, indicating the object to encode is a form. */
Type MAP_STRING_WILDCARD = Util.MAP_STRING_WILDCARD;
@ -76,12 +76,12 @@ public interface Encoder { @@ -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<Object> {
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {

6
core/src/main/java/feign/codec/StringDecoder.java

@ -1,5 +1,5 @@ @@ -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; @@ -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<String> {
@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;

14
core/src/main/java/feign/optionals/OptionalDecoder.java

@ -1,5 +1,5 @@ @@ -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; @@ -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<E> implements Decoder<E> {
final Decoder<E> delegate;
public OptionalDecoder(Decoder delegate) {
public OptionalDecoder(Decoder<E> 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<E> decodeOptional(Response response, Type type) throws IOException {
if (response.status() == 404 || response.status() == 204) {
return Optional.empty();
}

16
core/src/main/java/feign/stream/StreamDecoder.java

@ -1,5 +1,5 @@ @@ -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; @@ -44,16 +44,16 @@ import static feign.Util.ensureClosed;
* }</code>
* </pre>
*/
public final class StreamDecoder implements Decoder {
public final class StreamDecoder<E> implements Decoder<Stream<E>> {
private final Decoder iteratorDecoder;
private final Decoder<E> iteratorDecoder;
StreamDecoder(Decoder iteratorDecoder) {
StreamDecoder(Decoder<E> iteratorDecoder) {
this.iteratorDecoder = iteratorDecoder;
}
@Override
public Object decode(Response response, Type type)
public Stream<E> 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 { @@ -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<E> iterator =
(Iterator) iteratorDecoder.decode(response, new IteratorParameterizedType(streamType));
return StreamSupport.stream(
@ -76,8 +76,8 @@ public final class StreamDecoder implements Decoder { @@ -76,8 +76,8 @@ public final class StreamDecoder implements Decoder {
});
}
public static StreamDecoder create(Decoder iteratorDecoder) {
return new StreamDecoder(iteratorDecoder);
public static <E> StreamDecoder<E> create(Decoder<E> iteratorDecoder) {
return new StreamDecoder<>(iteratorDecoder);
}
static final class IteratorParameterizedType implements ParameterizedType {

4
core/src/test/java/feign/AlwaysEncodeBodyContractTest.java

@ -56,7 +56,7 @@ public class AlwaysEncodeBodyContractTest { @@ -56,7 +56,7 @@ public class AlwaysEncodeBodyContractTest {
String concatenate(String word1);
}
private static class AllParametersSampleEncoder implements Encoder {
private static class AllParametersSampleEncoder implements Encoder<Object> {
@Override
public void encode(Object object, Type bodyType, RequestTemplate template)
throws EncodeException {
@ -67,7 +67,7 @@ public class AlwaysEncodeBodyContractTest { @@ -67,7 +67,7 @@ public class AlwaysEncodeBodyContractTest {
}
}
private static class BodyParameterSampleEncoder implements Encoder {
private static class BodyParameterSampleEncoder implements Encoder<Object> {
@Override
public void encode(Object object, Type bodyType, RequestTemplate template)
throws EncodeException {

2
core/src/test/java/feign/FeignTest.java

@ -480,7 +480,7 @@ public class FeignTest { @@ -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,

2
core/src/test/java/feign/UtilTest.java

@ -298,7 +298,7 @@ public class UtilTest { @@ -298,7 +298,7 @@ public class UtilTest {
ParameterizedDecoder<?> PARAMETERIZED_DECODER_UNBOUND = null;
}
interface ParameterizedDecoder<T extends List<String>> extends Decoder {
interface ParameterizedDecoder<T extends List<String>> extends Decoder<Object> {
}

4
core/src/test/java/feign/examples/GitHubExample.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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<Object> {
private final Gson gson = new Gson();

10
dropwizard-metrics4/src/main/java/feign/metrics4/MeteredDecoder.java

@ -27,14 +27,14 @@ import feign.codec.Decoder; @@ -27,14 +27,14 @@ import feign.codec.Decoder;
/**
* Warp feign {@link Decoder} with metrics.
*/
public class MeteredDecoder implements Decoder {
public class MeteredDecoder<E> implements Decoder<E> {
private final Decoder decoder;
private final Decoder<E> decoder;
private final MetricRegistry metricRegistry;
private final MetricSuppliers metricSuppliers;
private final FeignMetricName metricName;
public MeteredDecoder(Decoder decoder, MetricRegistry metricRegistry,
public MeteredDecoder(Decoder<E> decoder, MetricRegistry metricRegistry,
MetricSuppliers metricSuppliers) {
this.decoder = decoder;
this.metricRegistry = metricRegistry;
@ -43,7 +43,7 @@ public class MeteredDecoder implements Decoder { @@ -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 { @@ -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(

10
dropwizard-metrics4/src/main/java/feign/metrics4/MeteredEncoder.java

@ -1,5 +1,5 @@ @@ -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; @@ -24,14 +24,14 @@ import feign.codec.Encoder;
/**
* Warp feign {@link Encoder} with metrics.
*/
public class MeteredEncoder implements Encoder {
public class MeteredEncoder<E> implements Encoder<E> {
private final Encoder encoder;
private final Encoder<E> encoder;
private final MetricRegistry metricRegistry;
private final MetricSuppliers metricSuppliers;
private final FeignMetricName metricName;
public MeteredEncoder(Encoder encoder, MetricRegistry metricRegistry,
public MeteredEncoder(Encoder<E> encoder, MetricRegistry metricRegistry,
MetricSuppliers metricSuppliers) {
this.encoder = encoder;
this.metricRegistry = metricRegistry;
@ -40,7 +40,7 @@ public class MeteredEncoder implements Encoder { @@ -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(

12
dropwizard-metrics5/src/main/java/feign/metrics5/MeteredDecoder.java

@ -25,16 +25,16 @@ import io.dropwizard.metrics5.MetricRegistry; @@ -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<E>} with metrics.
*/
public class MeteredDecoder implements Decoder {
public class MeteredDecoder<E> implements Decoder<E> {
private final Decoder decoder;
private final Decoder<E> decoder;
private final MetricRegistry metricRegistry;
private final MetricSuppliers metricSuppliers;
private final FeignMetricName metricName;
public MeteredDecoder(Decoder decoder, MetricRegistry metricRegistry,
public MeteredDecoder(Decoder<E> decoder, MetricRegistry metricRegistry,
MetricSuppliers metricSuppliers) {
this.decoder = decoder;
this.metricRegistry = metricRegistry;
@ -43,7 +43,7 @@ public class MeteredDecoder implements Decoder { @@ -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 { @@ -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())

10
dropwizard-metrics5/src/main/java/feign/metrics5/MeteredEncoder.java

@ -1,5 +1,5 @@ @@ -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; @@ -24,14 +24,14 @@ import io.dropwizard.metrics5.Timer.Context;
/**
* Warp feign {@link Encoder} with metrics.
*/
public class MeteredEncoder implements Encoder {
public class MeteredEncoder<E> implements Encoder<E> {
private final Encoder encoder;
private final Encoder<E> encoder;
private final MetricRegistry metricRegistry;
private final MetricSuppliers metricSuppliers;
private final FeignMetricName metricName;
public MeteredEncoder(Encoder encoder, MetricRegistry metricRegistry,
public MeteredEncoder(Encoder<E> encoder, MetricRegistry metricRegistry,
MetricSuppliers metricSuppliers) {
this.encoder = encoder;
this.metricRegistry = metricRegistry;
@ -40,7 +40,7 @@ public class MeteredEncoder implements Encoder { @@ -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(

4
gson/src/main/java/feign/gson/GsonDecoder.java

@ -1,5 +1,5 @@ @@ -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; @@ -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<Object> {
private final Gson gson;

4
gson/src/main/java/feign/gson/GsonEncoder.java

@ -1,5 +1,5 @@ @@ -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; @@ -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<Object> {
private final Gson gson;

4
jackson-jaxb/src/main/java/feign/jackson/jaxb/JacksonJaxbJsonDecoder.java

@ -1,5 +1,5 @@ @@ -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; @@ -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<Object> {
private final JacksonJaxbJsonProvider jacksonJaxbJsonProvider;
public JacksonJaxbJsonDecoder() {

4
jackson-jaxb/src/main/java/feign/jackson/jaxb/JacksonJaxbJsonEncoder.java

@ -1,5 +1,5 @@ @@ -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; @@ -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<Object> {
private final JacksonJaxbJsonProvider jacksonJaxbJsonProvider;
public JacksonJaxbJsonEncoder() {

2
jackson-jr/src/main/java/feign/jackson/jr/JacksonJrDecoder.java

@ -30,7 +30,7 @@ import java.util.Map; @@ -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<Object> {
@FunctionalInterface
interface Transformer {

2
jackson/src/main/java/feign/jackson/JacksonDecoder.java

@ -28,7 +28,7 @@ import feign.Response; @@ -28,7 +28,7 @@ import feign.Response;
import feign.Util;
import feign.codec.Decoder;
public class JacksonDecoder implements Decoder {
public class JacksonDecoder implements Decoder<Object> {
private final ObjectMapper mapper;

4
jackson/src/main/java/feign/jackson/JacksonEncoder.java

@ -1,5 +1,5 @@ @@ -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; @@ -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<Object> {
private final ObjectMapper mapper;

4
jackson/src/main/java/feign/jackson/JacksonIteratorDecoder.java

@ -1,5 +1,5 @@ @@ -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; @@ -54,7 +54,7 @@ import static feign.Util.ensureClosed;
* }</code>
* </pre>
*/
public final class JacksonIteratorDecoder implements Decoder {
public final class JacksonIteratorDecoder implements Decoder<Object> {
private final ObjectMapper mapper;

4
jaxb/src/main/java/feign/jaxb/JAXBDecoder.java

@ -1,5 +1,5 @@ @@ -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; @@ -47,7 +47,7 @@ import org.xml.sax.SAXException;
* The JAXBContextFactory should be reused across requests as it caches the created JAXB contexts.
* </p>
*/
public class JAXBDecoder implements Decoder {
public class JAXBDecoder implements Decoder<Object> {
private final JAXBContextFactory jaxbContextFactory;
private final boolean namespaceAware;

4
jaxb/src/main/java/feign/jaxb/JAXBEncoder.java

@ -1,5 +1,5 @@ @@ -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; @@ -41,7 +41,7 @@ import feign.codec.Encoder;
* The JAXBContextFactory should be reused across requests as it caches the created JAXB contexts.
* </p>
*/
public class JAXBEncoder implements Encoder {
public class JAXBEncoder implements Encoder<Object> {
private final JAXBContextFactory jaxbContextFactory;

2
json/src/main/java/feign/json/JsonDecoder.java

@ -49,7 +49,7 @@ import static java.lang.String.format; @@ -49,7 +49,7 @@ import static java.lang.String.format;
* System.out.println(contributors.getJSONObject(0).getString("login"));
* </pre>
*/
public class JsonDecoder implements Decoder {
public class JsonDecoder implements Decoder<Object> {
@Override
public Object decode(Response response, Type type) throws IOException, DecodeException {

2
json/src/main/java/feign/json/JsonEncoder.java

@ -48,7 +48,7 @@ import static java.lang.String.format; @@ -48,7 +48,7 @@ import static java.lang.String.format;
* github.create("openfeign", "feign", contributor);
* </pre>
*/
public class JsonEncoder implements Encoder {
public class JsonEncoder implements Encoder<Object> {
@Override
public void encode(Object object, Type bodyType, RequestTemplate template)

14
micrometer/src/main/java/feign/micrometer/MeteredDecoder.java

@ -25,20 +25,20 @@ import java.util.Optional; @@ -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<E>} with metrics.
*/
public class MeteredDecoder implements Decoder {
public class MeteredDecoder<E> implements Decoder<E> {
private final Decoder decoder;
private final Decoder<E> decoder;
private final MeterRegistry meterRegistry;
private final MetricName metricName;
private final MetricTagResolver metricTagResolver;
public MeteredDecoder(Decoder decoder, MeterRegistry meterRegistry) {
public MeteredDecoder(Decoder<E> decoder, MeterRegistry meterRegistry) {
this(decoder, meterRegistry, new FeignMetricName(Decoder.class), new FeignMetricTagResolver());
}
public MeteredDecoder(Decoder decoder, MeterRegistry meterRegistry, MetricName metricName,
public MeteredDecoder(Decoder<E> decoder, MeterRegistry meterRegistry, MetricName metricName,
MetricTagResolver metricTagResolver) {
this.decoder = decoder;
this.meterRegistry = meterRegistry;
@ -47,7 +47,7 @@ public class MeteredDecoder implements Decoder { @@ -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<MeteredBody> body = Optional.ofNullable(response.body())
.map(MeteredBody::new);
@ -55,7 +55,7 @@ public class MeteredDecoder implements Decoder { @@ -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;

10
micrometer/src/main/java/feign/micrometer/MeteredEncoder.java

@ -23,18 +23,18 @@ import static feign.micrometer.MetricTagResolver.EMPTY_TAGS_ARRAY; @@ -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<E> implements Encoder<E> {
private final Encoder encoder;
private final Encoder<E> encoder;
private final MeterRegistry meterRegistry;
private final MetricName metricName;
private final MetricTagResolver metricTagResolver;
public MeteredEncoder(Encoder encoder, MeterRegistry meterRegistry) {
public MeteredEncoder(Encoder<E> encoder, MeterRegistry meterRegistry) {
this(encoder, meterRegistry, new FeignMetricName(Encoder.class), new FeignMetricTagResolver());
}
public MeteredEncoder(Encoder encoder,
public MeteredEncoder(Encoder<E> encoder,
MeterRegistry meterRegistry,
MetricName metricName,
MetricTagResolver metricTagResolver) {
@ -45,7 +45,7 @@ public class MeteredEncoder implements Encoder { @@ -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));

12
mock/src/test/java/feign/mock/MockClientSequentialTest.java

@ -1,5 +1,5 @@ @@ -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 { @@ -72,16 +72,16 @@ public class MockClientSequentialTest {
}
class AssertionDecoder implements Decoder {
class AssertionDecoder<E> implements Decoder<E> {
private final Decoder delegate;
private final Decoder<E> delegate;
public AssertionDecoder(Decoder delegate) {
public AssertionDecoder(Decoder<E> 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 { @@ -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")

10
mock/src/test/java/feign/mock/MockClientTest.java

@ -68,16 +68,16 @@ public class MockClientTest { @@ -68,16 +68,16 @@ public class MockClientTest {
}
class AssertionDecoder implements Decoder {
class AssertionDecoder<E> implements Decoder<E> {
private final Decoder delegate;
private final Decoder<E> delegate;
public AssertionDecoder(Decoder delegate) {
public AssertionDecoder(Decoder<E> 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 { @@ -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",

4
sax/src/main/java/feign/sax/SAXDecoder.java

@ -1,5 +1,5 @@ @@ -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; @@ -46,7 +46,7 @@ import static feign.Util.resolveLastTypeParameter;
* .target(MyApi.class, "http://api");
* </pre>
*/
public class SAXDecoder implements Decoder {
public class SAXDecoder implements Decoder<Object> {
private final Map<Type, ContentHandlerWithResult.Factory<?>> handlerFactories;

2
soap/src/main/java/feign/soap/SOAPDecoder.java

@ -81,7 +81,7 @@ import feign.jaxb.JAXBContextFactory; @@ -81,7 +81,7 @@ import feign.jaxb.JAXBContextFactory;
* @see SOAPErrorDecoder
* @see SOAPFaultException
*/
public class SOAPDecoder implements Decoder {
public class SOAPDecoder implements Decoder<Object> {
private final JAXBContextFactory jaxbContextFactory;

2
soap/src/main/java/feign/soap/SOAPEncoder.java

@ -83,7 +83,7 @@ import feign.jaxb.JAXBContextFactory; @@ -83,7 +83,7 @@ import feign.jaxb.JAXBContextFactory;
* The JAXBContextFactory should be reused across requests as it caches the created JAXB contexts.
* </p>
*/
public class SOAPEncoder implements Encoder {
public class SOAPEncoder implements Encoder<Object> {
private static final String DEFAULT_SOAP_PROTOCOL = SOAPConstants.SOAP_1_1_PROTOCOL;

Loading…
Cancel
Save