forked from OpenFeign/feign
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGsonCodec.java
More file actions
43 lines (33 loc) · 905 Bytes
/
Copy pathGsonCodec.java
File metadata and controls
43 lines (33 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package feign.gson;
import com.google.gson.Gson;
import java.io.IOException;
import java.lang.reflect.Type;
import javax.inject.Inject;
import feign.RequestTemplate;
import feign.Response;
import feign.codec.Decoder;
import feign.codec.Encoder;
/**
* @deprecated use {@link GsonEncoder} and {@link GsonDecoder} instead
*/
@Deprecated
public class GsonCodec implements Encoder, Decoder {
private final GsonEncoder encoder;
private final GsonDecoder decoder;
public GsonCodec() {
this(new Gson());
}
@Inject
public GsonCodec(Gson gson) {
this.encoder = new GsonEncoder(gson);
this.decoder = new GsonDecoder(gson);
}
@Override
public void encode(Object object, RequestTemplate template) {
encoder.encode(object, template);
}
@Override
public Object decode(Response response, Type type) throws IOException {
return decoder.decode(response, type);
}
}