Skip to content

Commit 1e1bdb2

Browse files
authored
Removes use of internal gson class (OpenFeign#452)
Turns out an api was added a very long time ago to do what we do in gson without use of internal apis. See OpenFeign#449
1 parent ced133e commit 1e1bdb2

2 files changed

Lines changed: 5 additions & 17 deletions

File tree

gson/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ GitHub github = Feign.builder()
1515
### Map<String, Object> and Numbers
1616
The default constructors of `GsonEncoder` and `GsonDecoder` decoder numbers in
1717
`Map<String, Object>` as Integer type. This prevents reading `{"counter", "1"}`
18-
as `Map.of("counter", 1.0)`. This uses an internal class in gson.
18+
as `Map.of("counter", 1.0)`.
1919

20-
If you want the default behavior, or cannot use gson internal classes (ex in
21-
OSGi), please use the constructors that accept a Gson object.
20+
To change this, please use constructors that accept a Gson object.

gson/src/main/java/feign/gson/DoubleToIntMapTypeAdapter.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,20 @@
1616
package feign.gson;
1717

1818
import com.google.gson.Gson;
19-
import com.google.gson.InstanceCreator;
2019
import com.google.gson.TypeAdapter;
21-
import com.google.gson.internal.ConstructorConstructor;
22-
import com.google.gson.internal.bind.MapTypeAdapterFactory;
2320
import com.google.gson.reflect.TypeToken;
2421
import com.google.gson.stream.JsonReader;
2522
import com.google.gson.stream.JsonWriter;
26-
2723
import java.io.IOException;
28-
import java.lang.reflect.Type;
29-
import java.util.Collections;
3024
import java.util.Map;
3125

3226
/**
3327
* Deals with scenario where Gson Object type treats all numbers as doubles.
3428
*/
3529
public class DoubleToIntMapTypeAdapter extends TypeAdapter<Map<String, Object>> {
36-
37-
final static TypeToken<Map<String, Object>> token = new TypeToken<Map<String, Object>>() {
38-
};
39-
40-
private final TypeAdapter<Map<String, Object>>
41-
delegate =
42-
new MapTypeAdapterFactory(new ConstructorConstructor(
43-
Collections.<Type, InstanceCreator<?>>emptyMap()), false).create(new Gson(), token);
30+
private final TypeAdapter<Map<String, Object>> delegate =
31+
new Gson().getAdapter(new TypeToken<Map<String, Object>>() {
32+
});
4433

4534
@Override
4635
public void write(JsonWriter out, Map<String, Object> value) throws IOException {

0 commit comments

Comments
 (0)