You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (e.getCause() !=null&& e.getCause() instanceofIOException) {
52
-
throwIOException.class.cast(e.getCause());
53
-
}
54
-
throw e;
55
-
}
56
-
}
57
-
};
58
-
}
59
-
}
60
-
```
61
-
Feign doesn't offer a built-in json decoder as you can see above it is very few lines of code to wire yours in. If you are a jackson user, you'd probably thank us for not dragging in a dependency you don't use.
38
+
Feign includes a fully functional json codec in the `feign-gson` extension. See the `Decoder` section for how to write your own.
62
39
63
-
#### Type-specific Decoders
64
-
The generic parameter of `Decoder.TextStream<T>` designates which The type parameter is either a concrete type, or `Object`, if your decoder can handle multiple types. To add a type-specific decoder, ensure your type parameter is correct. Here's an example of an xml decoder that will only apply to methods that return `ZoneList`.
If specified as the last argument of a method `IncrementalCallback<T>` fires a background task to add new elements to the callback as they are decoded. Think of `IncrementalCallback<T>` as an asynchronous equivalent to a lazy sequence.
73
42
@@ -91,36 +60,6 @@ IncrementalCallback<Contributor> printlnObserver = new IncrementalCallback<Contr
When using an `IncrementalCallback<T>`, you'll need to configure an `IncrementalDecoderi.TextStream<T>` or a general one for all types (`IncrementalDecoder.TextStream<Object>`).
96
-
97
-
Here's how to wire in a reflective incremental json decoder:
if (e.getCause() !=null&& e.getCause() instanceofIOException) {
111
-
throwIOException.class.cast(e.getCause());
112
-
}
113
-
throw e;
114
-
}
115
-
}
116
-
jsonReader.endArray();
117
-
}
118
-
};
119
-
}
120
-
```
121
-
122
-
123
-
124
63
### Multiple Interfaces
125
64
Feign can produce multiple api interfaces. These are defined as `Target<T>` (default `HardCodedTarget<T>`), which allow for dynamic discovery and decoration of requests prior to execution.
126
65
@@ -134,6 +73,14 @@ You can find [several examples](https://github.com/Netflix/feign/tree/master/fei
134
73
135
74
### Integrations
136
75
Feign intends to work well within Netflix and other Open Source communities. Modules are welcome to integrate with your favorite projects!
76
+
### Gson
77
+
[GsonModule](https://github.com/Netflix/feign/tree/master/feign-gson) adds default encoders and decoders so you get get started with a json api.
78
+
79
+
Integration requires you pass `new GsonModule()` to `Feign.create()`, or add it to your graph with Dagger:
[JAXRSModule](https://github.com/Netflix/feign/tree/master/feign-jaxrs) overrides annotation processing to instead use standard ones supplied by the JAX-RS specification. This is currently targeted at the 1.1 spec.
139
86
@@ -151,6 +98,60 @@ Integration requires you to pass your ribbon client name as the host part of the
151
98
```java
152
99
MyService api =Feign.create(MyService.class, "https://myAppProd", newRibbonModule());
153
100
```
101
+
102
+
### Decoders
103
+
The last argument to `Feign.create` allows you to specify additional configuration such as how to decode a responses, modeled in Dagger.
104
+
105
+
If any methods in your interface return types besides `void` or `String`, you'll need to configure a `Decoder.TextStream<T>` or a general one for all types (`Decoder.TextStream<Object>`).
106
+
107
+
The `GsonModule` in the `feign-gson` extension configures a (`Decoder.TextStream<Object>`) which parses objects from json using reflection.
108
+
109
+
Here's how you could write this yourself, using whatever library you prefer:
The generic parameter of `Decoder.TextStream<T>` designates which The type parameter is either a concrete type, or `Object`, if your decoder can handle multiple types. To add a type-specific decoder, ensure your type parameter is correct. Here's an example of an xml decoder that will only apply to methods that return `ZoneList`.
The last argument to `Feign.create` allows you to specify additional configuration such as how to decode a responses, modeled in Dagger.
134
+
135
+
When using an `IncrementalCallback<T>`, if `T` is not `Void` or `String`, you'll need to configure an `IncrementalDecoder.TextStream<T>` or a general one for all types (`IncrementalDecoder.TextStream<Object>`).
136
+
137
+
The `GsonModule` in the `feign-gson` extension configures a (`IncrementalDecoder.TextStream<Object>`) which parses objects from json using reflection.
138
+
139
+
Here's how you could write this yourself, using whatever library you prefer:
Feign can be directly wired into Dagger which keeps things at compile time and Android friendly. As opposed to exposing builders for config, Feign intends users to embed their config in Dagger.
0 commit comments